Skip to content

Instantly share code, notes, and snippets.

@smohadjer smohadjer/
Last active Mar 7, 2020

What would you like to do?
PHP tips and tircks

Use foreach to loop arrays

foreach (array_expression as $value)
foreach (array_expression as $key => $value)

in_array — Checks if a value exists in an array

count — Count all elements in an array, or something in an object

array_key_exists() checks if the given key or index exists in an array

$array1 = array("Orange" => 100, "Apple" => 200, "Banana" => 300, "Cherry" => 400);
if (array_key_exists("Banana", $array1))
  echo "Array Key exists...";

Null coalescing operator

$name = $_GET['name'] ?? 'john doe';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.