MoFish Posted March 1, 2016 Share Posted March 1, 2016 Hi, I'm trying to structure an array into the following format: Array ( [Barrow-in-Furness] => Array ( [11] => Isle of Walney [12] => Dalton-in-Furness [13] => Askam-in-Furness [14] => Millom [15] => Ulverston ) ) I can get my data into this format using the following code which arranges the array correctly and works, however i get lots of errors due to the array_push requiring two parameters. I have tried to resolve this by adding more parameters, but it keeps changing the array structure i require. Warning: array_push() expects at least 2 parameters, 1 given in /home5/whammond/public_html/sharpmedia/gts/controller.inc.php on line 114 Strict Standards: Only variables should be passed by reference in /home5/whammond/public_html/sharpmedia/gts/controller.inc.php on line 116 Warning: array_push() expects at least 2 parameters, 1 given in /home5/whammond/public_html/sharpmedia/gts/controller.inc.php on line 116 Strict Standards: Only variables should be passed by reference in /home5/whammond/public_html/sharpmedia/gts/controller.inc.php on line 116 array_push($array[$location]); array_push($array[$location][$i]); array_push($array[$location][$i]=$connection->sheets[0]["cells"][$i][2]); Would anyone be able to advise on how i can manipulate the three lines of code above to maintain the array structure i require above, and also fix the warnings . error messages received. Thanks, MoFish Quote Link to comment https://forums.phpfreaks.com/topic/300915-structuring-array-help/ Share on other sites More sharing options...
Solution Jacques1 Posted March 1, 2016 Solution Share Posted March 1, 2016 (edited) array_push() appends a value to an array, so there are necessarily two arguments (or more). If you have less, your code makes no sense. It seems what you actually want to do is store a value at a specific index, which has nothing to do with array_push(): $array[$location][$i] = $connection->sheets[0]["cells"][$i][2]; Edited March 1, 2016 by Jacques1 1 Quote Link to comment https://forums.phpfreaks.com/topic/300915-structuring-array-help/#findComment-1531612 Share on other sites More sharing options...
MoFish Posted March 1, 2016 Author Share Posted March 1, 2016 Thank you for your prompt response Jacques1. Yes, you are right that worked perfectly. I think i got a little confused with the array_push which took me off track. Thanks again. MoFish Quote Link to comment https://forums.phpfreaks.com/topic/300915-structuring-array-help/#findComment-1531613 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.