Jump to content
php.lv forumi

function() un array


didy

Recommended Posts

Velos izveidot funkciju kura ietilpst vairaki defineti masiivi.

Pie funkcijas izvades noradot vienu no masiviem un redzet izdrukatu masiivu rezultatu.

 

<?php
function auglis($auglis){
$apple = array('apals', 'sarkans', 'koka');
$kartupelis = array('ovals', 'bruns', 'zemee');
echo "$auglis[0], $auglis[1], $auglis[2]";
}
auglis($auglis = $apple);
?>

 

Izlabojiet, ko daru nepareizi.

Edited by didy
Link to comment
Share on other sites

Ja pareizi sapratu, tad palasi par Variable Variables (http://lv.php.net/language.variables.variable) un reku vajadzētu būt tam, ko tu tur mēģini izzīlēt:

 

<?php
function auglis($auglis){
$apple = array('apals', 'sarkans', 'koka');
$kartupelis = array('ovals', 'bruns', 'zemee');
$auglis = $$auglis;
echo "$auglis[0], $auglis[1], $auglis[2]";
}
auglis('apple');
?>

 

un starp citu kartupelis ir dārzenis, nevis auglis :)

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...