Jump to content

structuring array help


MoFish
Go to solution Solved by Jacques1,

Recommended Posts

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

Link to comment
Share on other sites

  • Solution

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 by Jacques1
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.