代码区项目交易流程

Foreach php statement


I need to combine two foreach statement into one for example

foreach ($categories_stack as $category) foreach ($page_name as $value)

I need to add these into the same foreach statement

Is this possible if so how?

thanks

(I am not sure I have understood your question completely. I am assuming that you want to iterate through the two lists in parallel)

You can do it using for loop as follows :

$n = min(count($category), count($value)); for($c = 0; $c < $n; $c = $c + 1){ $categories_stack = $category[$c]; $pagename = $value[$c]; ... }

To achieve the same with foreach you need a function similar to python's zip() function.

In Python, it would be :

for categories_stack, pagename in zip(categories, values): print categories_stack, pagename

Sincephp doesn't have a standard zip() function, you'll have to write such a function on your own or go with the for loop solution.

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

点击收藏

LAST Real-time Unique Input Validation with VueJS and Laravel Python 包管理及虚拟环境的应用(一) NEXT