-3

I'm not understanding why the array:

<? $data = array( 'items[0][type]' => 'screenprint'); ?>

Is not the same as

<? echo $data['items'][0]['type']; ?>

I'm trying to add to the array but can't seem to figure out how?

Digi Jeff
  • 169
  • 1
  • 4
  • 15

2 Answers2

3
array( 'items[0][type]' => 'screenprint')

This is an array which has one key which is named "items[0][type]" which has one value. That's not the same as an array which has a key items which has a key 0 which has a key type. PHP doesn't care that the key kinda looks like PHP syntax, it's just one string. What you want is:

$data = array('items' => array(0 => array('type' => 'screenprint')));

I hope it's obvious that that's a very different data structure.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • The API I am working with is saying that doesn't work. It says the top example I gave is how it's suppose to be formatted. But I need to push to that array with more keys like: items[1][type] => screenprint – Digi Jeff Oct 03 '14 at 09:11
  • 2
    I don't know your API and it hardly makes sense. – deceze Oct 03 '14 at 09:18
  • How do I get an array change from this: Array ( [0] => Array ( [items[0][type]] => screenprint ) [1] => Array ( [items[1][type]] => screenprint ) [2] => Array ( [items[2][type]] => screenprint ) ) to this: Array ( [items[0][type]] => screenprint [items[1][type]] => screenprint [items[2][type]] => screenprint ) – Digi Jeff Oct 03 '14 at 09:50
0

It should be:

$data = [
    'items' => [['type' => 'screenprint']]
];
echo $data['items'][0]['type'];
halfer
  • 19,824
  • 17
  • 99
  • 186
TBI
  • 2,789
  • 1
  • 17
  • 21