like
Code: Select all
$a = array();
// May be using for loop
for($i=0; $i < 5; $i++)
$a[0];
$a[0][0];
$a[0][0][0];
$a[0][0][0][0][0];Moderator: General Moderators
Code: Select all
$a = array();
// May be using for loop
for($i=0; $i < 5; $i++)
$a[0];
$a[0][0];
$a[0][0][0];
$a[0][0][0][0][0];Code: Select all
$a = array();
$a[0] = array();
$a[0][0] = array();
$a[0][0][0] = array();
$a[0][0][0][0] = array();
$a[0][0][0][0][0] = array();Code: Select all
$a[0];
$a[0][0];Code: Select all
$a[0] = array();Code: Select all
$a[0][0] = ARRAY();Code: Select all
$a = array();Code: Select all
$a[0] = array();Code: Select all
<?php
$depth = 5;
eval('$array = '.str_repeat('array(', $depth).str_repeat(')', $depth).';');
print_r($array);
?>Code: Select all
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
)
)
)
)
)Code: Select all
function make_n_ary($depth) {
return ($depth < 2) ?
array() :
array(make_n_ary($depth - 1));
}
$a = make_n_ary(10);
print_r($a);Code: Select all
$str = '4 + r - 5 = 8';Code: Select all
$segment = array();
for($i=0; $i < strlen($str); $i++)
$segment[$i] = $str[$i];Code: Select all
$rhs = '';
for($j=$equalSignIndex+1; $i< sizeof($segment); $i++){
$rhs =. $segment[$i]; // Get the right hand side numbers which is 8- 4 + 5
}
return eval("return $rhs;"); // gives the result of 9Code: Select all
$segment[0] = '((2 + 1) * t )';
$segment[0][0] = '(2 + 1)';
$segment[0][1] = '*';
$segment[0][2] = 't';
$segment[1] = '+' // We have come out from parentheses so we want to store in new index
$segment[2] = '5';
$segment[3] = '=';
$segment[4] = '8';You can't do that. You are assigning a string AND an array to $segment[0]. You could achieve something similar to this with an associative array. I don't know if you are even taking the right approach to making this application.keenlearner wrote:Code: Select all
$segment[0] = '((2 + 1) * t )'; $segment[0][0] = '(2 + 1)'; $segment[0][1] = '*'; $segment[0][2] = 't'; $segment[1] = '+' // We have come out from parentheses so we want to store in new index $segment[2] = '5'; $segment[3] = '='; $segment[4] = '8';