<?php
$myArray = [
array(
"fname" => "Sudhir",
"lname" => "Gour",
"age" => 27,
"city" => "Jaipur",
"state" => "Jaipur",
"country" => "India"
) ,
array(
"fname" => "Sudhir",
"lname" => "Gour",
"age" => 27,
"city" => "Jaipur",
"state" => "Jaipur",
"country" => "India"
)
];
// array_push($myArray , ["fruit" => "Peach"]); // Inserting an array.
// array_push($myArray , "secondLast" , "last"); // Inserting Multiple Elements.
// $myArray["Subject"] = "Laravel"; // Inserting a key value pair manuallly.
//// There is no way to insert a key value pair of element to insert into an associate array using array_push() method.
// array_push($myArray , array("Reporter" => "Himanshu"));
// print_r($myArray);
$input = array(
"name" => "Sudhir",
"ans" => true
);
print_r(count(array_diff_key($myArray[0] , $input)));
if(count(array_diff_keys($myArray[0] , $input)) != 0){
echo("Keys don't match to perform array_push");
}
else{
array_push($myArray , $input);
}
To embed this program on your website, copy the following code and paste it into your website's HTML: