wizardmili.blogg.se

Foreach php
Foreach php











foreach php

Both of these methods of using foreach are explained in the last part of this tutorial.

FOREACH PHP CODE

Let me know if you have any questions on how my code works. The foreach loop is used to iterate through array elements in PHP. Since we are passing which value from the array we need you only need this to get your question get_question($question)

foreach php

Another thing that I changed is what variables you're passing to the function. PHP will automatically add keys to your array as you add more in the future. On your functions.php I removed the hard-coded $questions and replaced it with $questions.

foreach php

After that we can call our $question variable which uses your function to just get the question from your array. The break statement can be used to come out from the loop. It is slower than the traditional loop in performance. It is a newer way with lesser code to iterate over an array. On your html/php page you would call your function with the specific part of the array that you want ($question = get_question( $questions) ). It is one of the original ways of iterating over an array. I fixed a couple issues you had with your code. "" return $output } $questions = array() $questions= array( "question" => 'IN GERMAN - WHAT DOES THE WORD "SAMMELN" MEAN?', "hint-one" => "JOHN LIEBT ES, BRIEFMARKEN SAMMELN", "hint-two" => "TO ACCUMULATE AS A HOBBY OR FOR STUDY", "answer-one" => "TARGET", "answer-two" => "COLLECT", "answer-three" => "SAMPLE", "correct" => "answer-two" ) ?>













Foreach php