Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,456 members, 7,958,366 topics. Date: Wednesday, 25 September 2024 at 01:15 PM |
Nairaland Forum / Science/Technology / Webmasters / Php Oop Quick Quiz (2143 Views)
Php Oop Video / Php Poop Quick Quiz :: Merging Multipart Arrays / Moving To Oop Javascript/php Class Module Creation & Instantiation (2) (3) (4)
Php Oop Quick Quiz by Nobody: 12:21pm On Jul 16, 2011 |
Scenario: <?phpComment: But of course, the above code will not run. Question: What do i add to the code to make it work? and why? Please post the correction to win the quiz. |
Re: Php Oop Quick Quiz by lojik(m): 11:09pm On Jul 16, 2011 |
;d |
Re: Php Oop Quick Quiz by Nobody: 12:45am On Jul 17, 2011 |
N wa o, mr lojik, na you don clock all the nairaland post. Well, since no one chose to answer it sha, it is the object function or call or wharever that does that. If you have used some APIs like Joomla, Drupal and some other ones you will notice some arrays are presented this way: In drupal sometimes, we can say <?php global $user; if($user->uid) {echo "Hola $user->name | Logout";} else {echo "Hola Guest | Please login";} ?> Oh well, the answer to the quiz is: <?phpor <?php My framework uses such a technique as well. The framework is almost ready. All the extensions are working fine - modules, themes and stuffs. However, i want to give it a form API - to allow for easier code management, followed by some users API - then i will publish the work so far on dhtmlframework.com and create a new thread for it. |
Re: Php Oop Quick Quiz by sisqology(m): 2:31am On Jul 17, 2011 |
ahh, na wah o, you post question, u ansa am yourself |
Re: Php Oop Quick Quiz by Nobody: 9:05am On Jul 17, 2011 |
that was a good question i feel bad for not coming online to answer that most frameworks do that converting arrays to Object. e,g JDatabase::loadObjectList(); |
Re: Php Oop Quick Quiz by Nobody: 9:14am On Jul 17, 2011 |
Well, thank you for admitting that it was a good quiz. Well, i am kinda itching to start my new framework thread. But i have to upload first before i do that. The critical stuff i am adding to my framework is the form API very much similar to the drupal FORM API by 90%. |
Re: Php Oop Quick Quiz by binkabir(m): 9:11am On Jul 18, 2011 |
*dhtml: hello, drupal Form Api is cool but have a little look at that of Yii Framework its much better. |
Re: Php Oop Quick Quiz by Nobody: 1:07pm On Jul 18, 2011 |
For now, i just want to have a form api. With time and with some contributions, i will improve on it. A framework is easier to extend compared to a cms. Working alone is quite killing atimes. . . . |
Re: Php Oop Quick Quiz by binkabir(m): 3:23pm On Jul 18, 2011 |
a solution that is more advanced <?php class arrayClass { public function __construct( $array = array() ) { foreach( $array as $key => $value ) { if( is_array($value) && count($value) > 0 ) $this->$key = new arrayClass( $value ); else $this->$key = $value; } } } //Usage $p = array('a'=>'apple', 'b'=>'ball', 'others'=>array('c'=>'cup','d'=>'donkey')); $newObject = new arrayClass($p); echo $newObject->a . "<br>" ; echo $newObject->others->c; ?> |
Re: Php Oop Quick Quiz by Nobody: 4:36pm On Jul 18, 2011 |
Yeeeepa! you don use sledgehammer kill mosquito! It looks like you need work to do, ok, let me give you an advanced work to do: $form= array(That is a multi-level/multi-dimensional array and also ehm paired or as you say - associative. Now, i want you to write a function that can search and replace so you search for any key e.g fulltext, and replace with babes. array_replace_val('fulltext',"Babes",$form); |
Re: Php Oop Quick Quiz by binkabir(m): 4:45pm On Jul 18, 2011 |
*dhtml: i dey laugh lolllllllllllllllllllllllllll? i will recursively search either using a preg_match or array_search i have somethings doing i will get back later , |
Re: Php Oop Quick Quiz by Nobody: 4:56pm On Jul 18, 2011 |
Okay, till you return then. . . .i was thinking by now you for don solve am. . . |
Re: Php Oop Quick Quiz by binkabir(m): 4:58pm On Jul 18, 2011 |
in short take am <? $form= array( '#type' => 'select', '#title' => 'Display of XML feed items', '#default_value' => "teaser", '#options' => array( 'title' => 'Titles only', 'teaser' => array(user=>'Tony',pass=>'ayo'), 'fulltext' => 'Full text', ), '#description' => 'Global setting for the length of XML feed items that are output by default.', ); function ArraytoObject($array=array()){ foreach($array as $k=>$v){ if(is_array($v) && count($v)>0){ $k = strtolower($k); $array[$k]=(object)$v; } } return (object)$array; } $q = ArraytoObject($form) ; if(property_exists($q,''teaser'')){ $q->teaser->user = "binkabir'; } else throw new Exception ($e){ echo "dis one no be object see the error wey you cos ". $e; } |
Re: Php Oop Quick Quiz by Nobody: 7:10pm On Jul 18, 2011 |
Lol. . .this one na oop amigo! |
Re: Php Oop Quick Quiz by binkabir(m): 9:27am On Jul 19, 2011 |
*dhtml: |
(1) (Reply)
There's A Harry Styles Filter On Snapchat But Nobody Noticed / I Will Create A Professional Website/blog 4 You With Just 5k, ENTER HERE / Mtn Collect Sms Allows You To Send A Message While The Receiver Pays
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26 |