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

Home » Imported messages » comp.lang.php » list() Struktur auslagern
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: list() Struktur auslagern [message #176756 is a reply to message #176700] Sun, 22 January 2012 06:19 Go to previous messageGo to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma:
Senior Member
Erwin Moller wrote:

> On 1/18/2012 5:34 PM, Maximilian Koch wrote:
>> ich möchte aus einer CSV datei die inhalte auslesen, diese können sich
^^^^^^^^^^^
>> jedoch mal ändern in der reihenfolge. und es wird danach umständlich an
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> mehreren orten im PHP Script die sache zu ändern..
>>
>> gäbe es nicht eine möglichkeit diese auszulegen..
>> […]
> [In English: I can read German a little, but not produce it.]
>
> You command:
> explode(";",$datenbank_temp);
> will explode on ;
>
> For example:
> $myPartsArray = explode(",","eins,zwei,drei");
>
> Now you have 3 elements in your array:
> $myPartsArray[0] <-- "eins"
> $myPartsArray[1] <-- "zwei"
> $myPartsArray[2] <-- "drei"
>
>
> Looking at your example you want to explode on "," and not on ";".
>
> Also: You use list(), which makes no sense like that.
> Explode() already returns an array, so you can just do:
>
> $dispoliste_datenstruktur = explode(",",$datenbank_temp);
>
> That way you'll have all in the array $dispoliste_datenstruktur.

That is correct, but beside the point, as the question was how to get rid of
the numeric indexes that are hard to maintain. The list() approach is
viable if list() is given more than one argument, one for each component of
the comma-separated value:

| > list($foo, $bar) = explode(',', 'baz,bla');
| > echo implode('#', array($foo, $bar));
| baz#bla

IOW, now $foo and $bar can be used in place of $dispoliste_datenstruktur[0]
and $dispoliste_datenstruktur[1], respectively. The drawback of this
approach is that all fields need to be present or a notice will be
generated:

$ php -a
Interactive mode enabled

<?php

list($foo, $bar) = explode(',', 'baz');
echo implode('#', array($foo, $bar));
PHP Notice: Undefined offset: 1 in - on line 3
PHP Stack trace:
PHP 1. {main}() -:0
baz#

Fortunately, list() appears to be ignoring too many elements RHS.

$ php -a
Interactive mode enabled

<?php

list($foo, $bar) = explode(',', 'foo,bar,baz');
echo implode('#', array($foo, $bar));
foo#bar

> In case I didn't answer your question at all, which is very possible,
> just ask again. :-)

You did not answer the question at all. I have marked the relevant part
that you overlooked.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(at)news(dot)demon(dot)co(dot)uk> (2004)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: HTTP headers and header()
Next Topic: Loading globals into classes
Goto Forum:
  

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

Current Time: Thu Nov 28 20:41:46 GMT 2024

Total time taken to generate the page: 0.03894 seconds