PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > returning an array
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
returning an array

Réponse
 
LinkBack Outils de la discussion
Vieux 20/06/2008, 15h43   #1
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut returning an array

I'd like to do this:

function makeAnArray(){
$array = array('one'=>'1','two'=array('more than one'=>'dimension'));

return $array;
}

$a = makeAnArray();

// $a is ('one'=>'1','two'=array('more than one'=>'dimension'))

But with the right syntax. How do I do this?

(in perl I'd return a reference and then do a type conversion)

Jeff
  Réponse avec citation
Vieux 20/06/2008, 15h55   #2
Iván Sánchez Ortega
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning an array

Jeff wrote:

> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));


$array = array('one'=>'1','two'=>array('more than one'=>'dimension'));


--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

A bus station is where buses stop. A train station is where trains stop. On
my desk, there is a workstation...
  Réponse avec citation
Vieux 20/06/2008, 16h12   #3
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning an array

Iván Sánchez Ortega wrote:
> Jeff wrote:
>
>> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));

>
> $array = array('one'=>'1','two'=>array('more than one'=>'dimension'));
>
>

Yes, a typo. The actual code though is drawing from an unserialized
file, so I know the syntax php generated is corrected is correct. I also
checked the array just before it got returned and it looked fine.

Are you saying that I can return an array that way?

Jeff
  Réponse avec citation
Vieux 20/06/2008, 16h15   #4
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning an array

On Jun 20, 4:12pm, Jeff <jeff@spam_me_not.com> wrote:
> Iván Sánchez Ortega wrote:
> > Jeff wrote:

>
> >> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));

>
> > $array = array('one'=>'1','two'=>array('more than one'=>'dimension'));

>
> Yes, a typo. The actual code though is drawing from an unserialized
> file, so I know the syntax php generated is corrected is correct. I also
> checked the array just before it got returned and it looked fine.
>
> Are you saying that I can return an array that way?


Yes, didn't you think of trying it?

I find it a lot quicker to try simple things like this out instead of
writing a post to a forum such as this.

  Réponse avec citation
Vieux 20/06/2008, 16h16   #5
Erwin Moller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning an array

Jeff schreef:
> Iván Sánchez Ortega wrote:
>> Jeff wrote:
>>
>>> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));

>>
>> $array = array('one'=>'1','two'=>array('more than one'=>'dimension'));
>>
>>

> Yes, a typo. The actual code though is drawing from an unserialized
> file, so I know the syntax php generated is corrected is correct. I also
> checked the array just before it got returned and it looked fine.
>
> Are you saying that I can return an array that way?
>
> Jeff


Yes,

$myArr = array (
1 => 12,
50 => "hello fifty",
"IamAssoc" => array(23,45,77),
"meToo" => array("one" => 1, "two" => 2)
)

is perfectly fine.

Regards,
Erwin Moller
  Réponse avec citation
Vieux 20/06/2008, 20h22   #6
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: returning an array

Captain Paralytic wrote:
> On Jun 20, 4:12 pm, Jeff <jeff@spam_me_not.com> wrote:


My apologies...

>> Iván Sánchez Ortega wrote:
>>> Jeff wrote:
>>>> $array = array('one'=>'1','two'=array('more than one'=>'dimension'));
>>> $array = array('one'=>'1','two'=>array('more than one'=>'dimension'));

>> Yes, a typo. The actual code though is drawing from an unserialized
>> file, so I know the syntax php generated is corrected is correct. I also
>> checked the array just before it got returned and it looked fine.
>>
>> Are you saying that I can return an array that way?

>
> Yes, didn't you think of trying it?


I tried this in a function in a class, and sprinkled in some echos to
track the data to see where the problem was.

When I try the very same script now, it works. Perhaps I made some
other mistake... Unfortunately, it's not the craziest thing (not
programming though) that's happened today!

Jeff
>
> I find it a lot quicker to try simple things like this out instead of
> writing a post to a forum such as this.
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11883 seconds with 14 queries