Last active
August 10, 2021 01:07
-
-
Save simongcc/8632996 to your computer and use it in GitHub Desktop.
PHP useful techniques
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
// foreach by default is using value after "as" | |
foreach( $num_posts as $value ): | |
// echo $value."<br>"; | |
endforeach; | |
// using foreach with key instead of value | |
foreach( array_keys( $num_posts ) as $key ): | |
// echo $key."<br>"; | |
endforeach; | |
// to do something specific to the key may use | |
// Reference: http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key | |
foreach( array_keys( $num_posts ) as $key ): | |
// echo $key."<br>"; | |
if(($key = array_search($del_val, $num_posts)) !== false) { | |
unset($num_posts[$key]); | |
} | |
endforeach; | |
// force to display errors | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
error_reporting(E_ALL); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment