![](/img/trans.png)
[英]How can i use next() or current() in laravel eloquent returned array?
[英]how can i get this output use current array data
您好,我目前有這個數組數據:
https://i.stack.imgur.com/QPLdd.png
而且,我需要循環輸出
Array
(
[post_title] => post 1
[post_category] => 3
)
Array
(
[post_title] => post 2
[post_category] => 3
)
注意:上圖為示例,請理解這是一個循環。
原始輸出:當然,最后一個數組在循環中。
Array
(
[post_title] => post 2
[post_category] => 3
)
非常感謝。
只需循環遍歷一個子數組並獲取子數組鍵,然后使用該鍵從所有子數組中添加
$arr = array(
array(
'post 1',
'post 2',
'post 3'
),
array(
3,
3,
4
)
);
$output = array();
foreach($arr[0] as $i => $element) {
$output[] = array(
$arr[0][$i],
$arr[1][$i]
);
}
echo '<pre>' . print_r($output, true) . '</pre>';
for ($i = 0; $i < count($arr); $i++){
echo "[post_title] => ". $arr[0][$i];
echo "[post_category] => ". $arr[1][$i];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.