Showing posts with label array function example. Show all posts
Showing posts with label array function example. Show all posts

array_diff function - how to compare two or more arrays in php

array_diff function - how to compare two or more arrays in php


array_difffunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array_diff function - how to compare two or more arrays in php</title>
</head>

<body>
    <h2 style="color:Navy; font-style:italic">php example: using aarray_diff function in php</h2>
    <hr width="500" align="left" color="DodgerBlue" />
    <br />

<?php 
 $ColorsList1=array("Red","Green","Blue","Tan");
 $ColorsList2=array("Red","Green","Snow","Tan");

 print_r($ColorsList1);
 echo "<br /><br />";
 print_r($ColorsList2);
 echo "<br /><br />";

 echo "Colors only present in first array";
 echo "<br />";

 echo "<div style='font-size:large;color:OrangeRed'>";
  print_r(array_diff($ColorsList1,$ColorsList2));
 echo "</div>";
?>

</body>
</html>




array_count_values function - how to get array values number of occurrences in php

array_count_values function - how to get array values number of occurrences in php


array_count_valuesfunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array_count_values function - how to get array values number of occurrences in php</title>
</head>

<body>
    <h2 style="color:Navy; font-style:italic">php example: using array_count_values function in php</h2>
    <hr width="525" align="left" color="DodgerBlue" />
    <br />

<?php 
 $Colors=array("Red","Green","Red","Tan","Red","Olive","Tan","Snow","Maroon","Blue");
 echo "<div style='font-size:large;color:OrangeRed'>";
  print_r(array_count_values($Colors));
 echo "</div>";
?>

</body>
</html>




array_combine function - how to creates an array by combining two arrays in php

array_combine function - how to creates an array by combining two arrays in php


array_combinefunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array_combine function - how to creates an array by combining two arrays in php</title>
</head>

<body>
    <h2 style="color:Navy; font-style:italic">php example: using array_combine function in php</h2>
    <hr width="525" align="left" color="DodgerBlue" />
    <br />

<?php 
 $KeysArray=array("FirstName","LastName","Age");
 $ValuesArray=array("Jenny","Jones","24");
 echo "<div style='font-size:large;color:OrangeRed'>";
  print_r(array_combine($KeysArray,$ValuesArray));
 echo "</div>";
?>

</body>
</html>




array_chunk function - how to splits an array into chunks of new arrays in php

array_chunk function - how to splits an array into chunks of new arrays in php


array_chunkfunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array_chunk function - how to splits an array into chunks of new arrays in php</title>
</head>

<body>
    <h2 style="color:Navy; font-style:italic">php example: using array_chunk function in php</h2>
    <hr width="525" align="left" color="DodgerBlue" />
    <br />

<?php 
 $Colors=array("Crimson","Snow","DodgerBlue","BurlyWood","SaddleBrown");
 print_r(array_chunk($Colors,2,true));
 echo "<br /><br />";
 print_r(array_chunk($Colors,2,false));
?>

</body>
</html>




array_change_key_case function - how to change array keys in lower case or upper case

array_change_key_case function - how to change array keys in lower case or upper case


array_change_key_casefunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array_change_key_case function - how to change array keys in lower case or upper case</title>
</head>

<body>
    <h2 style="color:OrangeRed; font-style:italic">php example: using array_change_key_case function in php</h2>
    <hr width="525" align="left" color="Orange" />
    <br />

<?php 
 $Employee["FirstName"]="Jenny";
 $Employee["LastName"]="Jones";
 $Employee["Age"]="26";
 print_r($Employee);
 echo "<br /><br />";
 print_r(array_change_key_case($Employee,CASE_UPPER));
 echo "<br /><br />";
 print_r(array_change_key_case($Employee,LOWER_UPPER));
?>

</body>
</html>




numeric array - how to create and use numeric array in php

numeric array - how to create and use numeric array in php


numericarray.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>numeric array - how to create and use numeric array in php</title>
</head>

<body>
    <h2 style="color:DodgerBlue; font-style:italic">php array example: using numeric array</h2>
    <hr width="400" align="left" color="CornFlowerBlue" />
    <br />

<?php 
 $Color[0]="Crimson";
 $Color[1]="RosyBrown";
 $Color[2]="MistyRose";
 $Color[3]="Olive";
 $Color[4]="OliveDrab";
 $Color[5]="Green";

 echo "<div style='height:50px;width:350px;Background-color:$Color[0]'>";
 echo "</div>";

 echo "<div style='height:50px;width:350px;Background-color:$Color[2]'>";
 echo "</div>";

 echo "<div style='height:50px;width:350px;Background-color:$Color[5]'>";
 echo "</div>";

?>

</body>
</html>




array sort function: how to sort array in ascending value order in php

array sort function: how to sort array in ascending value order in php


sortFunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array sort function: how to sort array in ascending value order in php</title>
</head>

<body>
    <h2 style="color:Seagreen; font-style:italic">php array function example: using sort function</h2>
    <hr width="550" align="left" color="Green" />
    <br />
 </div>
    <?php
  $Color = array("Red","Green","Blue","Orange","SeaGreen");
  echo '<div style="font-size:large; color:DarkRed;">';
   echo "Colors without sorting: ";
   print_r($Color);
  echo "</div>";
  echo "<br />";
  sort($Color);
  echo '<div style="font-size:large; color:DarkOrange;">';
   echo "Colors ascending sorting: ";
   print_r($Color);
  echo "</div>";
 ?>
</body>
</html>




how to create multi dimensional array in php

how to create multi dimensional array in php


MultiDimensionalArray.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>how to create multi dimensional array in php</title>
</head>

<body>
    <h2 style="color:Seagreen; font-style:italic">php function example: using multi dimensional array</h2>
    <hr width="550" align="left" color="Green" />
    <br />
 </div>
    <?php
  $Employees = array(
         "Employee1"=> array("FirstName"=>"Ben", "LastName"=>"forta"),
         "Employee2"=> array("FirstName"=>"Raymond", "LastName"=>"Roy")       
         );
  echo '<div style="font-size:large; color:Crimson;">';
   echo "Employee1 First Name: ";
   echo $Employees["Employee1"]["FirstName"];
   echo "<br />Employee2 First Name: ";
   echo $Employees["Employee2"]["FirstName"];
  echo "</div>";
 ?>
</body>
</html>




array function: how to use array function in php

array function: how to use array function in php


arrayfunction.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>array function: how to use array function in php</title>
</head>

<body>
    <h2 style="color:DeepPink; font-style:italic">php function example: How to use array function</h2>
    <hr width="550" align="left" color="Pink" />
    <br />
 </div>
    <?php
  $Student=array("FirstName"=>"Jenny","LastName"=>"Jones","Age"=>"23");
  echo '<div style="font-size:large; color:Green;">';
   echo "First Name: ";
   echo $Student["FirstName"];
   echo "<br />Last Name: ";
   echo $Student["LastName"];
   echo "<br />Age: ";
   echo $Student["Age"];
  echo "</div>";
 ?>
</body>
</html>