Last active
June 20, 2017 12:11
-
-
Save makoru-hikage/398605d5c82cb00ef2eb5f91db74a084 to your computer and use it in GitHub Desktop.
Shows the use of continue 2 and the problem with switch inside a loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function setSort(array $items){ | |
$columnOrders = []; | |
foreach ($items as $item) { | |
$itemStartsWithAlpha = preg_match('/^\W[A-Za-z]*/', $item); | |
if (! $itemStartsWithAlpha) { | |
$column = substr($item, 1); | |
switch (substr($item, 0, 1)) { | |
case '+': | |
$columnOrders[$column] = 'asc'; | |
continue 2; | |
break; | |
case '-': | |
$columnOrders[$column] = 'desc'; | |
continue 2; | |
break; | |
default: | |
continue 2; | |
} | |
} | |
$columnOrders[$column] = 'asc'; | |
} | |
$this->sort = $columnOrders; | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment