顯示具有 array 標籤的文章。 顯示所有文章
顯示具有 array 標籤的文章。 顯示所有文章

2016年7月26日 星期二

[PHP] find the Duplicate values in array using php


Return duplicate values in array using PHP

Example:


<?php

$a = array('1','2','5','8');
$b = array('2','3','4','5');
print_r(array_repeat(array_merge($a,$b)));

function array_repeat($arr){
    if(!is_array($arr))
        return $arr;    
$arr1 = array_unique($arr);    
$arr3 = array_diff_key($arr,$arr1);    
return array_unique($arr3);}



?>

Result:

array $a



array $b



array_merge($a,$b)


array_repeat(array_merge($a,$b))







2016年7月22日 星期五

[PHP] How to use Explode , Implode in PHP

Explode Function (PHP)

Break a string into an array


<?php
  $str = "time,clock,book,money";
  print_r (explode(",",$str));
?>

Result:
Array ( [0] => time [1] => clock [2] => book [3] => money )




Implode Function (PHP)


Join array elements with a string

<?php
  $arr = array('We','are','family','.');
  echo implode(" ",$arr);
?>

Result:

We are family .