Symfony\Component\DomCrawler\Form::getPhpValues PHP Method

getPhpValues() public method

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does.
public getPhpValues ( ) : array
return array An array of field values
    public function getPhpValues()
    {
        $values = array();
        foreach ($this->getValues() as $name => $value) {
            $qs = http_build_query(array($name => $value), '', '&');
            if (!empty($qs)) {
                parse_str($qs, $expandedValue);
                $varName = substr($name, 0, strlen(key($expandedValue)));
                $values = array_replace_recursive($values, array($varName => current($expandedValue)));
            }
        }

        return $values;
    }

Usage Example

Esempio n. 1
0
 public function testgetPhpValuesWithEmptyTextarea()
 {
     $dom = new \DOMDocument();
     $dom->loadHTML('
           <html>
               <form>
                   <textarea name="example"></textarea>
               </form>
           </html>
       ');
     $nodes = $dom->getElementsByTagName('form');
     $form = new Form($nodes->item(0), 'http://example.com');
     $this->assertEquals($form->getPhpValues(), array('example' => ''));
 }
All Usage Examples Of Symfony\Component\DomCrawler\Form::getPhpValues