Jump to content

explode array question


centenial

Recommended Posts

Hi,

 

I have a string, like this:

 

Userid1 Pass1

Userid2 Pass2

Userid3 Pass3

Userid4 Pass4

 

Each column is tab separated. I want to explode it into an array so that the userid will be the key, and the password the value. I tried to do it like this:

 

$array = explode("\t", $string); // Where $string is the string above.

 

However, this returned both the userid and the password as the value, and created an automatic key for each row. Can anyone help me?

 

Thanks,

 

Link to comment
https://forums.phpfreaks.com/topic/43304-explode-array-question/
Share on other sites

$otherArray = array();
foreach ($array AS $a)
{
    $temp = explode(" ",$a);
    $otherArray[$temp['0']] = $temp['1'];
}

 

echo print_r($otherArray);

 

If that returns the same thing as above, try splitting the original array with the "\n" operator instead of "\t"

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.