Reputation: 27
I'm writing a project with two php code blocks. How do I send a value of a variable from one php block to the other?
<?php
function display() {
$items = array(
'<a href="?item=cherry"> <img src= "img/cherries.jpg" width="150" height="150" alt="cherry"/></a>',
'<a href="?item=cherry"> <img src= "img/cherries.jpg" width="150" height="150" alt="cherry"/></a>',
'<a href="?item=lemon"> <img src="img/lemon.png" width="150" height="150" alt="lemon"></a>',
'<a href="?item=lemon"> <img src="img/lemon.png" width="150" height="150" alt="lemon"></a>',
'<a href="?item=lemon"> <img src="img/lemon.png" width="150" height="150" alt="lemon"></a>',
'<a href="?item=lemon"> <img src="img/lemon.png" width="150" height="150" alt="lemon"></a>',
'<a href="?item=lemon"> <img src="img/lemon.png" width="150" height="150" alt="lemon"></a>',
'<a href="?item=bar"> <img src="img/bar.jpg" width="150" height="150" alt="bar"></a>',
'<a href="?item=bar"> <img src="img/bar.jpg" width="150" height="150" alt="bar"></a>',
'<a href="?item=bar"> <img src="img/bar.jpg" width="150" height="150" alt="bar"></a>',
'<a href="?item=star"> <img src="img/star.png" width="150" height="150" alt="star"></a>',
'<a href="?item=star"> <img src="img/star.png" width="150" height="150" alt="star"></a>',
'<a href="?item=star"> <img src="img/star.png" width="150" height="150" alt="star"></a>',
'<a href="?item=star"> <img src="img/star.png" width="150" height="150" alt="star"></a>'
);
$num1 = $items[rand(0, 12)];
$num2 = $items[rand(0, 12)];
$num3 = $items[rand(0, 12)];
echo $num1;
echo $num2;
echo $num3;
}
display();
?>
<td align="left"><input type="text" name="credit" value="<?php
if (isset($_POST['spin'])) {
$t = $_POST['bet'];
$v = $_POST['credit'];
if($v >=0){
if ($t > $v) {
if ($num1 == "cherry" && $num2 == "cherry" && $num3 == "cherry"):
$v = $v + $t + 100;
endif;
if ($num1 == "lemon" && $num2 == "lemon" && $num3 == "lemon"):
$v = $v + $t + 10;
endif;
if ($num1 == "star" && $num2 == "star" && $num3 == "star"):
$v = $v + $t + 20;
endif;
if ($num1 == "bar" && $num2 == "bar" && $num3 == "bar"):
$v = $v + $t + 50;
endif;
$totalCredit = $v;
} else {
$totalCredit = ($v - $t);
}
}else{
$totalCredit = 0;
}
}
echo (isset($totalCredit)) ? $totalCredit : '100';
?>" readonly="true"id="credit"/></td>
I want to pass the value of num1 2 and 3 to the above php code block. How would I go about doing this>?
Upvotes: 0
Views: 115
Reputation: 780889
The function should return something:
return array($num1, $num2, $num3);
The second code block can then receive them in its own variables:
list ($num1, $num2, $num3) = display();
Upvotes: 4