ok, here is the situation I read in a file that has multiple data per line. I would like to put it into a multi dimensional array. Here is how I do it now so you can see.
foreach($file as $line)
{
$info = explode('|', $line);
echo " <tr>\n";
echo " <td>" . $info[0] . "</td>";
echo " <td>" . $info[1] . "</td>";
echo " <td>" . $info[2] . "</td>";
echo " <td>" . $info[3] . "</td>";
echo " </tr>\n";
$totHours += $info[2];
}
the $info array keeps 4 pieces of data from each line and spits them out. I still want to output them to the screen but I want it in an array so I know which line each one is on. Hope it makes sense...
How to put this infor into a multi dimensional array?
Moderator: General Moderators
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
- daven
- Forum Contributor
- Posts: 332
- Joined: Tue Dec 17, 2002 1:29 pm
- Location: Gaithersburg, MD
- Contact:
are there any standard characters between the pieces of information, or could you add them? If so, you can use a list in conjunction with split, explode, or preg_split
Code: Select all
<?php
$i=0;
$info=array();
foreach($file as $line){
$info[$i]=array();
$info[$i]=explode("|",$line);
$i++;
}
for($j=0;$j<$i;$j++){
echo " <tr>\n";
echo " <td>" . $info[$j][0] . "</td>";
echo " <td>" . $info[$j][1] . "</td>";
echo " <td>" . $info[$j][2] . "</td>";
echo " <td>" . $info[$j][3] . "</td>";
echo " </tr>\n";
}
?>-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
anyone? Here is how I set the buttons up:
$i=0;
$info=array();
foreach($file as $line){
$info[$i]=array();
$info[$i]=explode("|",$line);
$i++;
}
for($j=0;$j<$i;$j++){
echo " <tr>\n";
echo " <td>" . $info[$j][0] . "</td>";
echo " <td>" . $info[$j][1] . "</td>";
echo " <td>" . $info[$j][2] . "</td>";
echo " <td>" . $info[$j][3] . "</td>";
echo ' <td><input type="submit" value="Delete Entry"></td>'; //The delete button
echo " </tr>\n";
$totHours += $info[$j][2];
}
$i=0;
$info=array();
foreach($file as $line){
$info[$i]=array();
$info[$i]=explode("|",$line);
$i++;
}
for($j=0;$j<$i;$j++){
echo " <tr>\n";
echo " <td>" . $info[$j][0] . "</td>";
echo " <td>" . $info[$j][1] . "</td>";
echo " <td>" . $info[$j][2] . "</td>";
echo " <td>" . $info[$j][3] . "</td>";
echo ' <td><input type="submit" value="Delete Entry"></td>'; //The delete button
echo " </tr>\n";
$totHours += $info[$j][2];
}