Comparing user input and array values

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
AnMK
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 12, 2018 1:08 pm

Thu Apr 12, 2018 1:16 pm

Hello,
I am working on a project but i am stuck on retrieving the array data after the button is clicked.
Here I am creating an array with some data based on the $selected_val.

Code: Select all

if ($selected_val==500) {
                                    //new array to store the words

                                    $items = array();
                                        foreach($b as $w)

                                                {

                                                  if (($typewords[$w] >= 1) && ($typewords[$w]<= 500)){//check the frequency
                                                     $items[] = $w;//populate the array

                                                     $fillIn=str_ireplace($w, "<span><input type='text' id='emptyField' name='input[]'></span>",$w);
                                                        echo $fillIn;


                                                  }
                                                  else{
                                                    //null
                                                    $color = "#000000";//yellow
                                                       echo "<span style=\"color:$color\" ><font size='4'>$w</font> </span>";
                                                  }


                                                    

                                                }


                                                //shuffle($_SESSION['$items']);//shuffles the array of words everytime the page is refreshed
                                                array_change_key_case($items,CASE_LOWER);

                                                //echo implode(" ", $items);
                                                echo "<br><br>";




                                                foreach ($items as $item) {
                                                

                                                  echo "<span id='my_span1'><input type=checkbox id=ckb1 value=1 onclick=my_fun(1)><font size='4'>$item    </font></span>";

                                                }

                      
                                                array_change_key_case($items,CASE_LOWER);

                                                 echo "<br>";


                                                echo "<br>";
}

                                                

In this section I am creating an array of all user inputs and I want to compare the user input and the already created above array $items. However, when i click on the button it refreshes the page and shows only the code in the if function. Also the $items array appears empty.

Code: Select all

if(isset($_POST['submit2'])){

                                    $newArray=array();

                                              $array = filter_input_array(INPUT_POST);

                                                

                                                foreach (array_keys($array) as $fieldKey) {
                                                    foreach ($array[$fieldKey] as $key=>$value) {
                                                        $newArray[] = $value;
                                                    }
                                           

                                                }
                                                echo "<br>";

                                               array_change_key_case($items,CASE_LOWER);

                                                

                                                echo "<br>";
                                                print_r($newArray);
                                                print_r($items);
                                  }


Please, I am still a beginner and need to finish this task. Can you give me any advice?

chorn
php-forum Fan User
php-forum Fan User
Posts: 551
Joined: Fri Apr 01, 2016 2:18 am

Sat Apr 14, 2018 9:06 am

After reading this twice, i still don't get where your problem is. It looks like there is a lot unrelated code. Whats the exact comparing you wnat to do? Provide some example data.

AnMK
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Apr 12, 2018 1:08 pm

Tue Apr 24, 2018 2:52 pm

I managed to figure it out. :)

Post Reply