php convert array to object
$object = (object) $array;
php convert array to object
$object = (object) $array;
implode php
$array = array('banana', 'strawberry', 'apple');
comma_separated = implode(",", $array);
echo comma_separated; // banana,strawberry,apple
convert object to array php
<?php
class sample {
/* Member variables */
var $var1;
var $var2;
function __construct( $par1, $par2 )
{
$this->var1 = $par1;
$this->var2 = $par2;
}
}
// Creating the object
$myObj = new sample(1000, "second");
echo "Before conversion: \n";
var_dump($myObj);
// Converting object to associative array
$myArray = json_decode(json_encode($myObj), true);
echo "After conversion: \n";
var_dump($myArray);
?>
Output:
Before conversion:
object(sample)#1 (2) {
["var1"]=>
int(1000)
["var2"]=>
string(6) "second"
}
After conversion:
array(2) {
["var1"]=>
int(1000)
["var2"]=>
string(6) "second"
}
Array to String Conversion in PHP
$gadget = array( 'computer', 'mobile', 'tablet' );
echo implode($arr);
Convert an Array to a String in PHP
phpCopy<?php
$array = ["Lili", "Rose", "Jasmine", "Daisy"];
$JsonObject = json_encode($array);
echo "The array is converted to the Json string.";
echo "\n";
echo"The Json string is $JsonObject";
?>
php implode
$arr = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$arr);
// Outputs: 'Hello World! Beautiful Day!'
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us