php assign unique variable foreach iteration of array -


i want assign each set of array in foreach loop assigned in unique variable

i have formed array

array (     [0] => array         (             [title] => mobiles & accessories         )  [1] => array     (         [title] => mobile accessories     )  [2] => array     (         [title] => cables     )  ) 

array (     [0] => array         (             [title] => computers         ) [1] => array     (         [title] => tv & video accessories     )  [2] => array     (         [title] => cables     )  ) 

array (     [0] => array         (             [title] => home entertainment         )  [1] => array     (         [title] => video players & accessories     )  [2] => array     (         [title] => video accessories     )  [3] => array     (         [title] => cables     )  ) 

i want each array set in unique variables

like

$a = (     [0] => array         (             [title] => mobiles & accessories         ) [1] => array     (         [title] => mobile accessories     )  [2] => array     (         [title] => cables     )  )  $b = array (     [0] => array         (             [title] => computers         ) [1] => array     (         [title] => tv & video accessories     )  [2] => array     (         [title] => cables     )  )  $c = array (     [0] => array         (             [title] => home entertainment         ) [1] => array     (         [title] => video players & accessories     )  [2] => array     (         [title] => video accessories     )  [3] => array     (         [title] => cables     )  ) 

etc., please

you may looking "variable variables".

sometimes convenient able have variable variable names. is, variable name can set , used dynamically.

<?php // arrays $arri = [     ['title' => 'mobiles & accessories'],     ['title' => 'mobile accessories'],     ['title' => 'cables'] ]; $arrii = [     ['title' => 'computers'],     ['title' => 'tv & video accessories'],     ['title' => 'cables'] ]; $arriii = [     ['title' => 'home entertainment'],     ['title' => 'video players & accessories'],     ['title' => 'video accessories'],     ['title' => 'cables'] ];  // may access arrays through following names $names = array('a', 'b', 'c');  // arrays $arrays = array($arri, $arrii, $arriii);  // now, create variables named after $names array elements, // , associate each 1 corresponding array in $arrays defined order. for($i = 0; $i<count($names); $i++)     $$names[$i] = $arrays[$i];  // now, can access arrays using new names! echo "<pre>"; print_r($a); echo "<hr>"; print_r($b); echo "<hr>"; print_r($c); echo "</pre>"; ?> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -