-1

What is difference between $prefix=array(''=>''); and $prefix=array(); what exactly $prefix=array(''=>''); using for ?

3 Answers3

1

There isn't really a difference, both are arrays. The difference is, the latter has an array key. For instance,

$test1=array(1,2,3,4,5);
$test2=array('name'=>'bob','lastname'=>'fossil');

will return;

print_r($test1[0]);
//1
print_r($test2['name']." ".$test2['lastname']);
//bob fossil

Basically, it gives the value a name

key=>val

can be used like this

foreach($test2 as $val){
    echo$val;
}

//bob
//fossil
bashleigh
  • 8,813
  • 5
  • 29
  • 49
0

It's used for creating associative arrays

Patrick Webster
  • 290
  • 1
  • 7
0

No difference. first option creates an array with some elements at once, the second creates an empty array.

Vladislav
  • 81
  • 9