Ec (2); & lt ;? In the php tutorial, the simplest way is to get the final element value of the array & nbsp; the Code is as follows: copy the code method 1 $ urlwww.111cn.net. cc; $ tmpUrlexplode (., $ url); Output temurl to see print_r ($ tmpUrl); * result: & nbsp; the Code is copied as follows on behalf of script ec (2); script
// In the php tutorial, obtain the last element of the array.
The Code is as follows: |
|
// Method 1 $ Url = 'www .111cn.net. CC '; $ TmpUrl = explode ('.', $ url ); |
// Output the temurl.
Print_r ($ tmpUrl );
/*
Result:
The Code is as follows: |
|
Array ( [0] => www [1] => 111cn [2] => net [3] => cc ) |
*/
// Let's look at method 1.
The Code is as follows: |
|
Echo end ($ tmpUrl); // cc // Method 2 array Length $ Count = count ($ tmpUrl ); Echo $ tmpUrl [$ count-1]; // cc |
/*
Summary:
Method 1 uses the php internal function end, which is convenient and convenient,
Method 2: Use count to calculate the length of the array and then subtract one to obtain the corresponding value.
Original Site Article www.111cn.net
*/
?>