array_search

#1
Moin,
bin's noch. :)
kann man mir sagen warum ich

{ from: , to:}
{ from: , to:}
{ from: , to:}
{ from: , to:}
{ from: , to:}
{ from: , to:}

anstatt

{from: 1, to: 0}
{from: 2, to: 0}
{from: 0, to: 3}
{from: 3, to: 4}
{from: 4, to: 5}
{from: 4, to: 6}

habe?

PHP:
$nodeList = array ("K", "I", "J", "L", "M", "X", "Z");
$family = array(
            "source" => array ("I", "J", "K", "L", "M", "M"),
            "destination" => array ("K", "K", "L", "M", "X", "Z")
            );
           
//$N = count($family['source']);
$len = count($nodeList);

$key_source = array();
$key_destination = array();
$linesFamily = array();

for($i=0; $i<$len; $i++){
    $key_source[] = array_search('$family["source"][$i]', $nodeList);
    $key_destination[] = array_search('$family["destination"][$i]', $nodeList);
}

for($i=0; $i<$len; $i++){

    $linesFamily[] = '{  from: ' .$key_source[$i].',  to:' .$key_destination[$i]. '}';                                                         
}

echo "<pre>";
print_r($linesFamily);
echo "</pre>";
DANKE
 
Zuletzt bearbeitet:
#3
Hi

Ändere
Code:
$key_source[] = array_search('$family["source"][$i]', $nodeList);
zu
Code:
$key_source[] = array_search($family["source"][$i], $nodeList);
und das selbe auch in der nächsten Zeile
Vielen Dank hat geklappt. Ich hatte die Dokumentation mit diesem Bsp. betrachtet
PHP:
$array = array(0 => 'blau', 1 => 'rot', 2 => 'grün', 3 => 'rot');

$key = array_search('grün', $array);  // $key = 2;
$key = array_search('rot', $array);   // $key = 1;
Deswegen habe ich die ' ' bewahrt.