我試圖讓一個PHP腳本將由逗號分隔的數字列表分割成一個數組,然後我可以循環併爲列表中的每個數字執行一個命令。將一個變量拆分爲一個數組
所以我真正想要達到的是這個;
$numbers = "2564521,5451254"
$data = array($numbers)
但是這不適用於數組。
這是我到目前爲止;
$data = array(2564521,5451254);
//Our 'stepping' variable
$g = 0;
//Our rowcount
$rowcount = 0;
echo "<table cellspacing='0'>\r";
for ($i=0; $i<count($data);) {
$rowcount++;
echo " <tr>\r"; //New row
$g = $i + 3; //Set our nested limit
for(; $i<$g; $i++) { //nested for loop
if (!isset($data[$i])) { //Allow us to break on incomplete rows
break;
}
echo " <td style='border: 1px #000 solid;'>\r"; //Out put a cell
echo " Number: $data[$i]</p>\r";
echo " </td>\r";
echo "$data[$i]</p>\r";
$tonumbers = "$data[$i]";
//Execute command for each number
}
echo " </tr> \r"; //End New Row
}
echo "</table>\r";?>
I would appreciate any help, thanks!
um。什麼語言? – hvgotcodes 2012-01-15 23:45:44