Bruce Gust
asked on
How can I stuff the results of this for loop into an array?
Here's my array:
When I run this code...
...I get this:
I need to "dig" into the array like this:
if($data['column_name']==" screenings ubperiod")
{
echo "yes";
}
I keep getting an error that says I'm using an undefined index and I understand WHY I'm getting that error, I just don't know how to build my array in a manner that allows me to check specific values.
Ideally, I need the array to look like this:
0 => array ( 'id' => '1', 'column_name' => 'screeningsubperiod', 'column_data' => 'screeningsubperiod_data', ),
Right now, I'm getting a separate array for every column heading. How can I fix that and then how can I drill down into that array and check for specific values?
Capture.PNG
$my_array=array (
0 => array ( 'id' => '1', 'column_name' => 'screeningsubperiod', 'column_data' => 'screeningsubperiod_data', ),
1 => array ( 'id' => '2', 'column_name' => 'screeningperiodid', 'column_data' => 'screeningperiodid_data', ),
2 => array ( 'id' => '3', 'column_name' => 'screeningtime', 'column_data' => 'screeningtime_data', ),
3 => array ( 'id' => '4', 'column_name' => 'bfull', 'column_data' => 'bfull_data', ),
);
When I run this code...
<?php
$num=count($my_array);
$numberfields=count($my_array[0]);
$i=0;
foreach($my_array as $row)
{
foreach($row as $key=>$value)
{
$fieldname="";
$fieldvalue="";
$fieldname=$key;
$fieldvalue=$value;
//$data[$fieldname] = $fieldvalue;
$data[$i][$fieldname]=[$fieldvalue];
$i++;
}
}
var_dump($data);
?>
...I get this:
I need to "dig" into the array like this:
if($data['column_name']=="
{
echo "yes";
}
I keep getting an error that says I'm using an undefined index and I understand WHY I'm getting that error, I just don't know how to build my array in a manner that allows me to check specific values.
Ideally, I need the array to look like this:
0 => array ( 'id' => '1', 'column_name' => 'screeningsubperiod', 'column_data' => 'screeningsubperiod_data',
Right now, I'm getting a separate array for every column heading. How can I fix that and then how can I drill down into that array and check for specific values?
Capture.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER