php - 处理php数组
问题描述
我的产品具有多个选项值,例如颜色和尺寸。
输入:
$colors = ['red','black','blue'];
$sizes = ['large', 'medium', 'small'];
此输入的预期输出应该是 9 个变体,其中一个应该是:
['red', 'small'];
我是 PHP 新手,那么最好的方法是什么?
解决方案
我建议你做类似的事情:
$array1 = ['red', 'blue'];
$array2 = ['large', 'small'];
foreach ($array1 as $value1) {
foreach ($array2 as $value2) {
$myNewArray = [$value1, $value2];
// here you can print array
// print_r($myNewArray);
}
}
你会得到这个输出:
['red', 'large']
['red', 'small'] // here it's what you are looking for
['blue', 'large']
['blue', 'small']
推荐阅读
- java - 使用 java.nio.Files 或 java.io 类创建 java.io.BufferedWriter
- wso2 - 登录发布者或商店时未通过对等方身份验证
- android - 一些新添加的方法上未显示 Android Studio API 级别警告
- excel - Excel VBA 中的基本布尔问题:输出 -1
- swift - StackView 水平包装内容
- python - 使用 igraph python 查找图的巨型组件的直径和平均最短路径长度
- sql - 合并具有相同列值的行
- java - Why my Object ArrayList loop result is incorrect?
- python - 在opencv中应用索贝尔和拉普拉斯滤波器后的图像边缘检测
- java - Selenium 中 Action 类的 Keys.DELETE 没有被删除