0
//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

I have tried replace

$data['direct_sponsor_bonus_vals']=array('package_size'=>$x);

by

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

but still not working.

Update : I think the bug is at foreach loop. Need 2 of foreach loop. I tried:

foreach ($direct_sponsor_bonus_vals As $key => $value ) 
{
    foreach ($value As $key_inner => $value_inner)
    {
        echo $value_inner;   // whatever
    }
}

Still has bug error : Invalid argument supplied for foreach()

0

1 Answer 1

1

I didn't actually understand which part of your code meant for a view but I think this is what you are looking for

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'] . ","; 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.