PHP - diziden Ekran değişkenleri

0 Cevap php

I've very new to arrays and this is just beyond my understanding. How can I get the data out of this array and display it in an echo. I know this is an easy one! Thanks in advance! Here is the var_dump

array(2) { [0]=>  string(10) "John Smith" [1]=>  string(10) "Smithville" } 

ve aşağıdaki kod

$string = "John Smith Smithville";
$townlist = array("smithville", "janeville", "placeville");

function stringSeperation($string, $list)
{
    $result = array();

    foreach($list as $item)
    {
        $pos = strrpos(strtolower($string), strtolower($item));
        if($pos !== false)
        {
            $result = array(trim(substr($string, 0, $pos)), trim(substr($string, $pos)));
            break;
        }
    }

    return $result;
}

var_dump(stringSeperation($string, $townlist));

echo isim

şehir echo

Regards, -Dan

0 Cevap