#php

Adds a new item or items in front of an array.

array_unshift($awesome_array, "new item");
copy
#php#header

Changes document header and returns document data in JSON format.

header('Content-Type: application/json');
copy
#php

Lets you parse a URL and retrieve parts like scheme, hostname, port, path, query, fragment, username, and password.

$url_to_parse = "https://shortcode.dev/php-cheatsheet?var=hello#php-cheatsheet";
$parsed = parse_url($url_to_parse);

echo $parsed['scheme'];     // https
echo $parsed['hostname'];   // shortcode.dev
echo $parsed['port'];       // ie. 8080
echo $parsed['path'];       // /php-cheatsheet
echo $parsed['query'];      // var=hello
echo $parsed['fragment'];   // php-cheatsheet
copy
#php

Run the following command to get installed PHP version.

php -v
copy
#php

Print value to the view.

$day = "Monday"
print $day;
copy
#php

Print value in a readable format. Useful when fetching large objects or arrays.

print_r($someObject);
copy
#php

Push a new item or items at the end of an array.

array_push($awesome_array, "new item");
copy
#php#conditional

Ternary operator evaluates first parameter followed by two values. First value is returned when the condition is true otherwise the second value is returned.

// Condition ? True : False

$hour = 14;
($hour <= 12) ? "Morning" : "Afternoon";
copy
#php

Return all the data about a variable in a structured format.

var_dump($your_variable);
copy
Sitemap Git repository