0

I have a multi array, how do i access each individual item i.e. "profile title" and is there a way i could loop through the array and assign variable to each arrays values for example

$firstarray->name $firstarray->html

$secondarray->typeId

array(4) {
      [0]=>
      array(4) {
        ["name"]=>
        string(13) "profile title"
        ["html"]=>
        string(52) "<h2 class="entry-title" id="title">Your Profile</h2>"
        ["typeId"]=>
        string(1) "1"
      }
      [1]=>
      array(4) {
        ["name"]=>
        string(8) "username"
        ["html"]=>
        string(145) "<fieldset disabled><br><label for="nameinput">Username</label><input type="text" id="userName"class="form-control" placeholder="" ></fieldset><p>"
        ["typeId"]=>
        string(1) "1"
      }

2 Answers 2

3

Assuming your array is called $firstarray :

foreach ($firstarray as $row)
{
    echo $row['name']; // or $row->name;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Vincent's answer should help you access each element. However, to assign them, you need to use array_push

`array_push`(  $firstarray, array('key'=>'value','key1'=>'value1')   );


OR 


$firstarray[0]['key'] = 'something';
$firstarray[0]['key1'] = 'something else';

$firstarray[1]['key'] = 'something';
$firstarray[1]['key1'] = 'something else';

etc..


OR 

$firstarray[0] = $secondarray1;
$firstarray[1] = $secondarray2;

etc..

1 Comment

If that helped, consider upvoting or marking as answered. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.