Click here to Skip to main content
16,016,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
//declare array variable
$data['direct_sponsor_bonus_vals']=array('package_size'=>'');

// insert element to array
for ($x = 0; $x <= 10; $x++) {
    $data['direct_sponsor_bonus_vals']=array('package_size'=>$x);
}

//show output
foreach($direct_sponsor_bonus_vals As $key => $value )
{
    echo $value . ",";
}

Output :

10,

How to make Output become like below :

0,2,3,4,5,6,7,8,9,10

What I have tried:

I have tried replace
<pre>
    $data['direct_sponsor_bonus_vals']=array('package_size'=>$x);

by
$data['direct_sponsor_bonus_vals']['package_size'][] = $x;

but still not working.
Posted
Updated 1-May-20 10:09am

1 solution

Got the answer :
In a Controller
$array = null;

for ($x = 0; $x <= 10; $x++) {
    $array[]= array('package_size'=>$x);
}
//to send above array to view just do $data['direct_sponsor_bonus_vals'] = $array;

in a view
foreach($direct_sponsor_bonus_vals as $value)
{
    echo $value['package_size'] . ","; 
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900