1

Consider the below code to save data in array,

 
  arr[]['name'] = 'hello';
  arr[]['value'] = 2;
 

I am trying to store data in a 2 d array without mentioning the index. Consider the above name/value set, if i store like this.

Values are stored like


  arr[0]['name'] = 'hello';
  arr[1]['value'] = 2;

But below is the expected result


  arr[0]['name'] = 'hello';
  arr[0]['value'] = 2;

how do i do it without mentioning any index? is there any way to do this?

Thanks,

Balan

1 Answer 1

4

This happens because every time you use [] it creates a new key, to store multiple things in one key, insert an array:

$arr[] = array('name' => 'hello', 'value' => 2);
Sign up to request clarification or add additional context in comments.

Comments

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.