FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » array how is done
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
array how is done [message #183678] Sat, 09 November 2013 06:53 Go to next message
nawfer is currently offline  nawfer
Messages: 34
Registered: August 2011
Karma: 0
Member
if I have this code

foreach($models as $md)
{$articles[] = array($md->id,$md->name);}

with an example (really value) can explain how can to be the $models and
how is $articles[]
Re: array how is done [message #183679 is a reply to message #183678] Sat, 09 November 2013 07:54 Go to previous messageGo to next message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
nawfer, 2013-11-09 07:53:

> if I have this code
>
> foreach($models as $md)
> {$articles[] = array($md->id,$md->name);}
>
> with an example (really value) can explain how can to be the $models and
> how is $articles[]

I'm not sure if I understand what you want to know.

Well - $models may be an array of objects and $articles will be an array
of values:

<?php
class Model
{
public $id;
public $name;
}

$model1 = new Model();
$model1->id = 1;
$model1->name = "dog";

$model2 = new Model();
$model2->id = 2;
$model2->name = "cat";

$models = array(
$model1,
$model2
);

foreach($models as $md)
{
$articles[] = array($md->id, $md->name);
}

var_dump($models);
var_dump($articles);
?>


--
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de
Re: array how is done [message #183684 is a reply to message #183678] Sat, 09 November 2013 13:59 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
nawfer wrote:

> if I have this code
>
> foreach($models as $md)
> {$articles[] = array($md->id,$md->name);}
>
> with an example (really value) can explain how can to be the $models and
> how is $articles[]

<http://php.net/print_r>
<http://php.net/var_dump>
<http://www.catb.org/~esr/faqs/smart-questions.html>


PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom(at)94(dot)75(dot)214(dot)39>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: $dom->loadHTMLFile() error
Next Topic: IT company looking for skilled resources
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 16:09:01 GMT 2024

Total time taken to generate the page: 0.02714 seconds