using this loop code I want to dislay elements or items of expression like this , suppose 1 + 2*3 is the expression then by this loop I should get output like first it will display 1 then +2 should be display to user then * 3 should be displayed
but I am getting output like this
firstly its displaying
1+
+2
2 *
*3
so what should I do to display it like
1
+2
*3
and so on as per the expression
Tell us what the real problem is instead of asking about your attempted solution to the real problem. You are creating two variables that you don’t even use at all.
@benanamen basically I have stored expression in $expression which is generating randomly and I am displaying each item of that expression one by one in the manner that after displaying first item when next button is clicked then the next item should appear and visisble to user and current item should go to previous position which will not be visible to user, upto this its all working fine for me .
@benanamen Now the real Problem I am facing is that I am displaying only one item at a time i.e firstly its shows operand then on clicking next button its showing operator and so on. but I want to display it like this , if example 1 + 2 = 3 is expression then firstly 1 should appear then +2 should be appear and so on in same manner ,
Thats where I am confused. I 've used above logic but its not showing items like I have explained above , How can I do it?
hey thanks for help , I tried but its no showing any result now , btw I dont understands this “if the contents of $expression[] were known…”
probably thats why it is not working can you tell me ?
Why didn’t you try this? Works as expected if you have a slight change on the condition, and you can use the coalesce-operator to catch the undefined index. Output:
$expression = ['8','+','3','*','2'];
// fix the "missing" operator for the first number
array_unshift($expression, ' ');
// group number and operator together
$chunked = array_chunk($expression, 2);
// put it all together
echo array_reduce($chunked, function ($string, array $row) {
return $string . implode(' ', $row) . PHP_EOL;
}, '');
I dont think you understood what I was asking. You are still describing HOW you are attempting solving the task at hand.
I am guessing based on the class name slide-item what is really going on is that you have a slideshow of images that should cycle when you click a button. If so, that is what I was asking for.
yes, there is a slideshow but not of images, its of items in an expression i.e operands and operators are sliding one by one when click on button and in addition to this I have created a timer for this , its working fine
But I want it to display in the manner that first element that appear in slide should be opeand then after sliding the next two elements should appear on screen i.e operator and operand both together , its like a math quiz