- implode: documentation ( source)
- range: documentation ( source)
<?php
/*
Default from the book
*/
$a = range(3,9);
foreach ($a as $b) {
switch($b) {
case 3:
$b = 7;
case 7:
$b = 3;
default:
// do nothing
}
}
echo implode('-',$a) . PHP_EOL;
// Excerpt From: Lorna Mitchell. “Zend Certification Preparation Pack.” iBooks.
/*
Suggested alternate method from the book
*/
$a = range(3,9);
foreach ($a as $key => $b) {
switch($b) {
case 3:
$a[$key] = 7;
case 7:
$a[$key] = 3;
default:
// do nothing
}
}
echo implode('-',$a) - PHP_EOL;
/*
Second alternate by using $b by reference
*/
$a = range(3,9);
foreach ($a as &$b) {
switch($b) {
case 3:
$b = 7;
case 7:
$b = 3;
default:
// do nothing
}
}
echo implode('-',$a);