ππ£π§πππ‘ πΎπ€πππ§
Open in Telegram
1 876
Subscribers
No data24 hours
-37 days
-4230 days
Posts Archive
#php
Usage of Array Filter in Php
$numbers = [1, 2, 3, 4, 5];
$filtered = array_filter($numbers, function($value) {
return $value % 2 == 0; // Filter even numbers
});
print_r($filtered);
#php
Make Json Prettify in PHP
json_encode is a function to convert an array into json
JSON_PRETTY_PRINT is used to make json prettify
$data = array(
'name' => 'John Doe',
'age' => 30,
'email' => 'johndoe@example.com'
);
$json = json_encode($data, JSON_PRETTY_PRINT);
echo $json;
#php
Check a String either exist or not in Array
Using in_array() which return Boolean
function is_in_list($string, $array) {
return in_array($string, $array);
}
// Usage example:
$myArray = ["apple", "banana", "orange"];
$result = is_in_list("banana", $myArray);
echo $result ? "String exists in the array" : "String does not exist in the array";
#php
Trim string in PHP
using substr() function
$q = "hello this world";
$trimmed = substr($q, strpos($q, "this"));
echo $trimmed; // Output: "this world"
#php
Get length in PHP
1. Use strlen only with string
$string = "Hello";
$length = strlen($string);
echo $length; // Output: 5
2. Use count() when the value returns array or object
$array = [1, 2, 3, 4, 5];
$count = count($array);
echo $count; // Output: 5
#php
Replace String In PHP
$string = "hola this is what what";
$newString = str_replace("what", "why why", $string);
echo $newString; // Output: "hola this is why why why why"
#php
List Assignment in PHP
$string = "John|25";
[$name, $age] = explode("|", $string);
echo $name; // Output: John
PHP version >= 7.1
(If you are using older version then use list() construct )
$string = "John|25";
list($name, $age) = explode("|", $string);
echo $name; // Output: John
