The simplest way to use Check if an Array is Empty or Not in PHP example looks like this.
<?php
$arr = array( 'data1' => 34, 'data2' => 36 );
if(empty( $arr )){
echo 'empty array';
}else{
echo 'Not Empty Array';
}
?>
Output :- Not Empty Array
Here, in this code define PHP check array with the using empty() function example and apply along with the condition. Also, implement this method on your source code of functionality. According, have to how another example in the below section with empty() function.
How to check if an array is empty – empty()
$arrdata = array( 'red', 'black', 'white' );
if(!empty( $arrdata )){
echo 'Not empty data';
}else{
echo 'empty array data';
}
Now, display this example for using !empty() function. Firstly, Store an array of variables this is an index array then apply conditions to check array values are empty. The best example must apply anywhere on the page.
Hence, Keep scrolling down for the next chapter.
How to Push Associative Array in PHP
Usually, we give a basic example that how to push associative array in PHP, First, I have pushed a single key and value inside the associative array. After that, given some more examples like it multiple arrays pushing with the using PHP function.
$arr = array(
"name" => "Jonny",
"Mob" => "12345",
"Email" => "jonny123@gmail.com"
);
$arr['Address'] = array( "state" => "delhi", "country" => "India", "pincode" => "123854" );
echo "<pre>";
print_r($arr);
Output
Array
(
[name] => Jonny
[Mob] => 12345
[Email] => jonny123@gmail.com
[Address] => Array
(
[state] => delhi
[country] => India
[pincode] => 123854
)
)
So, this is the best simple example to add and push any type of array in your codes. Now, show you another example with the single key and value. check out the below section.
Array Push Multidimensional PHP
Hence, you can see until the concept to push of multidimensional array. Here, only created an array variable. Also, add on value in the same variable with the push other array key and value see this below.
$arr = array(
"name" => "jonh",
"Mob" => "588555",
"Email" => "jonh143@gmail.com"
);
$arr['Country'] = "United State";
array_push() function PHP Example
Here, provide a PHP function for the index array. Now, see how to insert a value inside the array with array_push() see below.
$arr = array('one', 'two', 'three');
array_push($arr, 'four');
Output :- Array ( [0] => one [1] => two [2] => three [3] => four )
Hence, Keep scrolling down to the next example.
[wlearnsmartcode]in_array() in PHP | Array Value Exists, Associative/Multidimensional
The in_array() example here. Basically array function searches any specific value from the array. Here, We provide in_array in PHP as well as added another example for array value exists with the help index array.
Also, share two examples of in_array associative array PHP and multidimensional. So, you can see the code in the below section.
$arr = array('php','java','python');
if ( in_array( 'java', $arr ) ) {
echo 'available';
}else{
echo 'not available';
}
Output :- Available
Although, apply this example for index array and created a $arr variable defined array.
Also, inserted some string values then apply if condition to check array value exists or not in the array. As well As mention output condition.
in_array Associative Array PHP
Similarly, In this example, and in array function only searches values that exist then condition true and false.
So you can see below example have applied for associative array and check value exists with the using in_array().
$arr = array('lang1' => 'php','lang2' => 'java','lang3' => 'python');
if ( in_array( 'java', $arr ) ) {
echo 'exists';
}else{
echo 'not exists';
}
in_array() Multidimensional
In this example, we applied for multidimensional arrays. Here, in this array, only one concept to searches value from the array.
Firstly, check the value that which array available value have mention array to array path by array values. and then find as this example display code.
$arr = array(
'lang1' => 'php',
'lang2' => 'java',
'lang3' => array( 'red','green','blue' )
);
if ( in_array( 'green', $arr['lang3'] ) ) {
echo 'exists';
}else{
echo 'not exists';
}
Hence, Keep scrolling down to the next example.
[wlearnsmartcode]is_array() | is Array PHP function With Example
Now, we give the best example of is array PHP and how to check an array is empty are not. As well as define what is_array() or how to use is_array() in PHP.
<?php
// $arr = 'This is not array only string';
$arr = array('computer','android','iphone','ipad');
if ( is_array($arr)) {
echo 'Available';
}else{
echo 'Not Available';
}
?>
Output:- Available
Here, Also given another example of is_array(). So, in this example passing string in a variable that must pass is array function. It means out will be of else condition check it below code.
is Array PHP function Example - is_array()
$arr = 'This is not array only string';
if ( is_array($arr)) {
echo 'Available';
}else{
echo 'Not Available';
}
Now output:- Not Available
Therefore, you can see this type out if you put this function is_array( $arr ). It means only give only boolean as true and false. Secondly, put this code anywhere with the condition and check that is an array or not. Also, Check this example empty()
Hence, Keep scrolling down to the next example.
[wlearnsmartcode]strrev() | PHP Reverse String | Example
The simplest PHP Reverse String example looks like this.
strrev("web learn smart");
Outputs - trams nrael bew
strrev() - How to Reverse a String
<?php
$str = "Change your string with the using this function";
echo strrev($str);
?>
In this chapter, I added an example for the PHP reverse string. So, you can apply this example and reverse each word character as well as possibly change a string.
Hence, Keep scrolling down for the next chapter.
[wlearnsmartcode]strlen() | String Length PHP | Example
The simplest string length PHP example looks like this.
<?php
echo strlen("First example of String");
?>
Outputs - 23
strlen() - Count length of string in PHP
$str = 'How to get string';
if ( strlen($str) < 50 ) {
echo $str;
}else{
echo "wrong";
}
In this chapter, you can see PHP strlen function. accordingly, get the length of the string with this example. Also, you can apply conditions with the use of common syntax. Also read about more information Submit Form without Page Refresh using Ajax jQuery PHP
Keep scrolling down for the next chapter.
[wlearnsmartcode]str_word_count() | Word limit in PHP | Example
The simplest way word limit in PHP example looks like this.
<?php
echo str_word_count("word count function");
?>
Outputs - 3
str_word_count() - Word count in PHP
$str = 'how to get word count';
if ( strlen($str) < 3) {
echo $str;
}else{
echo "string limit over";
}
In this chapter, you can see examples of a number of words in this string. Also, implement with the condition. Accordingly, you must apply and try this condition on your project for the string in PHP. How to Insert JSON data into MySQL using PHP
Hence, Keep scrolling down for the next chapter.
[wlearnsmartcode]