LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Php String to Array (https://www.linuxquestions.org/questions/programming-9/php-string-to-array-511688/)

joelhop 12-18-2006 02:52 PM

Php String to Array
 
I want to build an array from a single word using PHP:


If the word is: linux


I want the array to be:
Array
(
[0] => l
[1] => i
[2] => n
[3] => u
[4] => x

)

Is there a simple way to do this in php?

int0x80 12-18-2006 03:30 PM

PHP Code:

<?php

$os 
"GNU/Linux";
$arrOS str_split($os);
print_r($arrOS);

/**
 * Output:

Array
(
    [0] => G
    [1] => N
    [2] => U
    [3] => /
    [4] => L
    [5] => i
    [6] => n
    [7] => u
    [8] => x
)

*/
?>


joelhop 12-18-2006 03:39 PM

Thank you! That is exactly what I needed. str_split()


All times are GMT -5. The time now is 04:06 PM.