if ( isset($_POST['figuresugsubjectposition'])) {
$figuresubject_taxonomies = array( 'figuresugsubjectposition' => $_POST['figuresugsubjectposition']);
$figuresubject_taxonomies_from = array( 'figuresugsubjectfrom' => $_POST['figuresugsubjectfrom']);
foreach ( $figuresubject_taxonomies_from as $tax_name_from => $terms_from ) {
$figuresubject_taxonomies_from = $terms_from;
}
//this will return: Blue, White, Green, Yellow, Black.. etc
foreach ( $figuresubject_taxonomies as $tax_name => $terms ) {
$figuresubject_taxonomies = $terms;
}
//this will return: yes, yes, no, yes, yes.. etc
}
我$figuresubject_taxonomies_fnl
只希望第二个字符串中的颜色为“是”。在上面的示例中,$figuresubject_taxonomies_fnl
应回显:蓝色,白色,黄色,黑色...等。
如果您不介意丢失数组中的原始键,则可以执行以下操作:
<?php
$colours = array('black', 'orange', 'yellow');
$yes_no = array('yes', 'no', 'yes');
$combined = array_combine($colours, $yes_no);
$filtered = array_filter($combined, function($x) { return $x === 'yes'; });
$result = array_keys($filtered));
现在$result
将是以下数组:
Array
(
[0] => black
[1] => yellow
)
array_combined
返回一个新数组,该数组由键数组(您的颜色)和值数组(“ yes”或“ no”)组成。array_filter
仅返回回调函数返回的元素true
。
另外,您可以只使用一个循环:
$result = array();
for ($i = 0; $i < count($colours); ++$i) {
if ($yes_no[$i] === 'yes') $result[] = $colours[$i];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句