note 118979 added to language.types.object

From: Date: Fri, 11 Mar 2016 10:27:40 +0000
Subject: note 118979 added to language.types.object
Groups: php.notes 
Request: Send a blank email to php-notes+get-205137@lists.php.net to get a copy of this message
<!--Example shows how to convert array to stdClass Object and how to access its value for display --> <?php $num = array("Garha","sitamarhi","canada","patna"); //create an array $obj = (object)$num; //change array to stdClass object echo "<pre>"; print_r($obj); //stdClass Object created by casting of array $newobj = new stdClass();//create a new $newobj->name = "India"; $newobj->work = "Development"; $newobj->address="patna"; $new = (array)$newobj;//convert stdClass to array echo "<pre>"; print_r($new); //print new object ##How deals with Associative Array $test = [Details=>['name','roll number','college','mobile'],values=>['Naman Kumar','100790310868','Pune college','9988707202']]; $val = json_decode(json_encode($test),false);//convert array into stdClass object echo "<pre>"; print_r($val); echo ((is_array($val) == true ? 1 : 0 ) == 1 ? "array" : "not an array" )."</br>"; // check whether it is array or not echo ((is_object($val) == true ? 1 : 0 ) == 1 ? "object" : "not an object" );//check whether it is object or not ?> ---- Server IP: 72.52.91.14 Probable Submitter: 45.127.195.86 ---- Manual Page -- http://php.net/manual/en/language.types.object.php Edit -- https://master.php.net/note/edit/118979 Del: integrated -- https://master.php.net/note/delete/118979/integrated Del: useless -- https://master.php.net/note/delete/118979/useless Del: bad code -- https://master.php.net/note/delete/118979/bad+code Del: spam -- https://master.php.net/note/delete/118979/spam Del: non-english -- https://master.php.net/note/delete/118979/non-english Del: in docs -- https://master.php.net/note/delete/118979/in+docs Del: other reasons-- https://master.php.net/note/delete/118979 Reject -- https://master.php.net/note/reject/118979 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205137) next »