我需要在循环的每次迭代中存储三个字符串值,例如
$myArray = array();
foreach (..) {
$myArray[] = // I need to store as a single row or tuple three strings
}
foreach ($myArray as $arrayTuple)
// Do something with $arrayTuple.firstString, $arrayTuple.secondString and $arrayTuple.thirdString
我似乎无法理解如何使用关联数组执行此操作。
答案 0 :(得分:2)
如果我理解正确,那么你想要这样
$myArray = array();
foreach (..) {
$myArray[] = array("one","two","three");
}
答案 1 :(得分:0)
如果我理解正确的话,这对你有帮助:
foreach ($array as $key => $val) {
$myArray[$key] = $val;
}
答案 2 :(得分:0)
您可以使用array_push()
例如:
$myArray = array();
array_push($myArray, "one","two","three");
或者
$myArray = array();
array_push($myArray, "one:two:three");