note 47930 added to function.array

From: Date: Mon, 06 Dec 2004 08:55:33 +0000
Subject: note 47930 added to function.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-81426@lists.php.net to get a copy of this message
I copy this code for test: <?php $arr1 = ( 0 => array ("customer"=>"Client 1","Item a"), 1 => array ("customer"=>"Client 2","Item b") ); /*function to add elements*/ function addArray(&$array, $id, $var) { $tempArray = array( $var => $id); $array = array_merge ($array, $tempArray); } /*The same as above but the element is an array*/ function addArrayArr(&$array, $var, &$array1) { $tempArray = array($var => $array1); $array = array_merge ($array, $tempArray); } /*labels of our array or heders of the file*/ $keyarr = array("customer","item"); /*info that may you read from a file line 1 and 2*/ $valarr0 = array("Client 1","Item a"); $valarr1 = array("Client 2","Item b"); $numofrows = 2;/*In our case is just two lines*/ $tmpArray = array(); for($i = 0; $i < $numofrows; $i++){ $tmp = "valarr$i"; $tmpvar = ${$tmp};/*Using var of vars tricky tricky*/ foreach( $keyarr as $key=>$value){ addArray($tmparr,$tmpvar[$key],$value); } addArrayArr($finalarr,$i,$tmparr); } /*voila all it's perfectly ordered on finalarr*/ /*Here we just print the info but you can insert it into a database*/ echo "Customer: ".$finalarr[0]["customer"]."<br>"; echo "Item: ".$finalarr[0]["item"]."<br>"; echo "Customer: ".$finalarr[1]["customer"]."<br>"; echo "Item: ".$finalarr[1]["item"]."<br>"; ?> Any ideas why I get : Parse error: syntax error, unexpected T_DOUBLE_ARROW in c:\AppServ\www\test\test.php on line 3 ???? ---- Manual Page -- http://www.php.net/manual/en/function.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47930 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47930&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47930&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47930&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47930&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47930&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47930&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47930&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81426) next »