creating arrays in for loops.... without creating an endless loop that ruins my day!
Posted
by
Peter
on Stack Overflow
See other posts from Stack Overflow
or by Peter
Published on 2011-02-25T07:19:41Z
Indexed on
2011/02/25
7:24 UTC
Read the original article
Hit count: 236
Hey Guys,
Im starting with a csv varible of column names. This is then exploded into an array, then counted and tossed into a for loop that is supposed to create another array.
Every time I run it, it goes into this endless loop that just hammers away at my browser...until it dies. :(
Here is the code..
$columns = 'id, name, phone, blood_type';
<code>
$column_array = explode(',',$columns);
$column_length = count($column_array);
//loop through the column length, create post vars and set default
for($i = 0; $i <= $column_length; $i++)
{
//create the array iSortCol_1 => $column_array[1]...
$array[] = 'iSortCol_'.$i = $column_array[0];
}
</code>
What I would like to get out of all this is a new array that looks like so..
<code>
$goal = array(
"iSortCol_1" => "id",
"iSortCol_2" => "name",
"iSortCol_3" => "phone",
"iSortCol_4" => "blood_type"
);
</code>
© Stack Overflow or respective owner