php explode function

The return value of explode function is obvious in most cases, for example:

$ar=explode("\n","a\nb") return an array that has two elements: $ar[0]='a',$ar[1]='b';

But sometimes the return value may cause confusion. We will give some special php explode function examples below.

what do you think about the value of $ar=explode("\n",null)? Is $ar an empty array, or just a null? In fact ,$ar is an array with only one element and the element $ar[0] is an empty string(i.e. $ar[0]=”, not null) . For the difference between null and empty, please refer to this post.

What about $ar=explode("\n", "a")? It is an array of one element($ar[0]="a").

$ar=explode("\n","\n") is an array of two elements both of which are empty strings($ar[0]='',$ar[1]=''). Likewise, $ar=explode("\n","\n\n") is an array of three elements all of which are empty strings($ar[0]='',$ar[1]='',$ar[2]='').

$ar=explode("\n","a\r\nb") is an array of two elements($ar[0]="a\r",$ar[1]="b").

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply