Author Archives: Roopendra - Page 13
Count matching occurrences in php array
You can Count matching occurrences in php array using php array function array_count_values() Syntax: array array_count_values ( array $array ) array_count_values() returns an array using the values of array as keys and their frequency in array as values. Example:- <?php $array = array(1,"roopendra",1,"php","roopendra"); print_r(array_count_values($array)); ?> Above code will…
Validate URL in PHP
You can validate URL in PHP using regular expression or using validate filters Validate URL in PHP using regular expression: Example:- <?php // Write you regular expression pattern to match URL $pattern = @#\/%=~_|]/i"; // Assign URL to $URL variable $URL = ';name=roop'; // Check url using preg_match if (…
Changes in PHP Ternary Operator since PHP 5.3
Changes in PHP ternary operator since PHP Till PHP $varName = ($cond) ? $cond : 'false'; From PHP $varName = ($cond) ? : 'false'; No need to write condition for true. It will automatically taken $cond in true. Reference URL :- #
Post JSON data via PHP cURL
Post JSON data via PHP cURL We can Post JSON data via PHP curl by using header Content-Type: application/json in CURLOPT_HTTPHEADER. Below is working code demonstration of PHP curl with post json field. <?php $url = ''; $jsonString = json_encode(array("key" => "value")); // You can directly replace your JSON string with…



