Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #11769 > unrolled thread

array how is done

Started bynawfer <novalidsforspam@alt.al>
First post2013-11-09 07:53 +0100
Last post2013-11-09 14:59 +0100
Articles 3 — 3 participants

Back to article view | Back to comp.lang.php


Contents

  array how is done nawfer <novalidsforspam@alt.al> - 2013-11-09 07:53 +0100
    Re: array how is done Arno Welzel <usenet@arnowelzel.de> - 2013-11-09 08:54 +0100
    Re: array how is done Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-11-09 14:59 +0100

#11769 — array how is done

Fromnawfer <novalidsforspam@alt.al>
Date2013-11-09 07:53 +0100
Subjectarray how is done
Message-ID<1ds2wkcf5vcge$.kr8riwvisibu$.dlg@40tude.net>
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[]

[toc] | [next] | [standalone]


#11770

FromArno Welzel <usenet@arnowelzel.de>
Date2013-11-09 08:54 +0100
Message-ID<527DEA2E.7000109@arnowelzel.de>
In reply to#11769
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

[toc] | [prev] | [next] | [standalone]


#11773

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-11-09 14:59 +0100
Message-ID<2260503.bWFZx7Q4gD@PointedEars.de>
In reply to#11769
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@94.75.214.39>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web