php - Generating arrays inside for loop -
i have 2 following variables:
$contact_number=array('0123456','65321'); $msg="my text" ;
i trying create array following using above variables
$myarray =array( array("0" => "0123456", "1" => "my text"), array("0" => "65321", "1" => "my text") );
i have tried following code not creating exact array live above:
for($i=0; $i < count($contact_number); $i++ ) { $myarray[] =array(array("0" =>$contact_number[$i], "1" =>$msg),); } var_dump($myarray);
could please tell me how solve problem
you can loop through every contact number, , append message this:
$contact = array('0123456','65321'); $message = "my text" ; $array = array(); foreach($contact $value) { $array[] = array($value, $message); } var_export($array);
produces this:
array ( 0 => array ( 0 => '0123456', 1 => 'my text', ), 1 => array ( 0 => '65321', 1 => 'my text', ), )
Comments
Post a Comment