Loop over multiple arrays simultaneously: Difference between revisions

Content deleted Content added
No edit summary
Added PHP implementation
Line 361:
 
The <code>Z</code> operator stops emitting items as soon as the shortest input list is exhausted.
 
=={{header|PHP}}==
<lang PHP>$a = array('a', 'b', 'c');
$b = array('A', 'B', 'C');
$c = array('1', '2', '3'); //These don't *have* to be strings, but it saves PHP from casting them later
 
if ((sizeOf($a) !== sizeOf($b)) || (sizeOf($b) !== sizeOf($c))){
throw new Exception('All three arrays must be the same length');
}
foreach ($a as $key => $value){
echo "{$a[$key]}{$b[$key]}{$c[$key]}\n";
}</lang>
 
This implementation throws an exception if the arrays are not all the same length.
 
=={{header|PowerBASIC}}==