php - When To Use Object arrays over traditional arrays? -


in case more applicable use:

$obj_array = new arrayobject(array(), arrayobject::std_prop_list);  $obj_array->key = "value"; 

rather:

 $array = array();   $array['key'] = "value";  

now, these both different. can tell far, know after performing research see no real reason have preference on object arrays on traditional arrays..

so show me active example on how object arrays provide more benefit on normal array


in addition, i'm aware these object arrays new php.. database functions example, returns either array or single variables:

$query = $db->prepare("select * tbl col=?"); $query->bind_param('s',$variable);  $query->execute(); $query->bind_result($col1, $col2, $col3); $query->fetch(); $query->close();  

the above example returns contents singe variables.

so create object array using while loop:

$obj_array = new arrayobject(array(), arrayobject::std_prop_list); $key_creation = 0;     $query = $db->prepare("select username,password tbl col=?"); $query->bind_param('s',$variable);  $query->execute(); $query->bind_result($col1, $col2); while($query->fetch()){   $obj_array->$key_creation = array($col1,$col2);   $key_creation++; } $query->close(); 

arrayobject useful when have make code operates on object , code operates on array work together, assuming impossible or undesirable change 1 part of code behave other 1 does.

in practice, if in control of 1 or both parts of code not have need arrayobject , using gains nothing other reduced performance.

my personal opinion arrayobject should avoided plague, 1 in long list of half-baked "features" of dubious usefulness in php.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -