Jump to content
php.lv forumi

Funkcija kopa ar Assocativo masivu


Faks

Recommended Posts

Sveiki Damas un Kungi Problema ir sekojosa veicot funkcija darbiba ar assocativo masisvu vins man izvada ara tikai vienu assocativo masivu nevisu visus ara tapec atkal esu seit ceru ka jus varesiet man palidzesiet atrast gaismu bezgaligaja bedre !

function xy($x)
{
 $g = array('1' => 'Viens', '2' => 'Divi', '3' => 'Tris');
foreach($g as $t => $b)
{
 return $t.' -- '.$b.'<br>';
}
return $x;
}

#print_r($x);
echo xy($x);

Link to comment
Share on other sites

return komanda atgriež funkcijas vērtību, pārtraucot tālāku funkcijas izpildi. Rezultāts ko tu saņem ir tieši tāds, kādu tu prasi PHP.

function xy($x){
 $text = '';
 foreach($x as $t => $b){
   $text .=  $t . ' -- '.$b.'<br>';
 }
 return $text;
}

$x = array('1' => 'Viens', '2' => 'Divi', '3' => 'Tris');
echo xy($x);

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...