I’m starting with a csv variable 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';
$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++)
{
$array[] = $iSortCol_.$i = $column_array[$i];
//create the array iSortCol_1 => $column_array[1]...
//$array[] = 'iSortCol_'.$i = $column_array[0];
}
What I would like to get out of all this is a new array that looks like so..
$goal = array(
"iSortCol_1" => "id",
"iSortCol_2" => "name",
"iSortCol_3" => "phone",
"iSortCol_4" => "blood_type"
);
I think it’s because you’re assigning the value of $column_array[0] to $i AND using it as the loop index. Use another variable to do that, otherwise it just goes on and on.
EDIT Tested and pasted output
Working code, just tested it on local
This will output
Is this not what you want?