asp function split of corresponds to php function explode of

  • 2021-11-29 06:11:59
  • OfStack


<?php
// Utilization  explode  Function to split a string into an array 
$source = "hello1,hello2,hello3,hello4,hello5";// Separate strings by commas 
$hello = explode(',',$source);
for($i=0;$i<count($hello);$i++){
echo $hello[$i];echo "</br>";
}
?>

Intercept to remove the last/first character


$newstr = substr($str,0,strlen($str)-1); 

Get the specific data of the array


  $date = "04,30"; 
  list($month, $day) = split ('[,.-]', $date); 
  echo "Month: $month; Day: $day;<br />\n";

Remove duplicate element values array_unique () from the array


<meta charset="utf-8" />
<?php 
$a1="206,206,206,201,206,201";
//$array = explode(',', $a1); // Strings to form an array 
$array1=implode(",",array_unique(explode(',', $a1)));
 print_r($array1);
?>

How can an array index value be incremented from 0 again


<?php
  $a=array("a"=>"Cat","b"=>"Dog","c"=>"Horse");
  print_r(array_values($a));
  //  Output: 
  // Array ( [0] => Cat [1] => Dog [2] => Horse )
?>

Count the number of array elements


$a="303,304,305,306,307";
$a = explode(',',$a);
echo count($a);

JS split


<script language="javascript"> 
str="2,2,3,5,6,6"; // This is 1 String  
var strs= new Array(); // Definition 1 Array  
strs=str.split(","); // Character segmentation  
for (i=0;i<strs.length ;i++ ) 
{ 
document.write(strs[i]+"<br/>"); // Segmented character output  
} 
</script> 

The explode () function splits a string into an array.


//  Example  1 $pizza = "piece1 piece2 piece3 piece4 piece5 piece6"; 
$pieces = explode(" ", $pizza); 
echo $pieces[0]; // piece1 
echo $pieces[1]; // piece2 

The implode () function combines the elements of the array into a string.


$array = array('a' => 1, 'b'=>2, 'c'=>3, 'd'=>4);
$string = implode("-",$array)
echo $string;
//====  The result is: 1-2-3-4;

Summarize


Related articles: