php - How can I run a function with an array of checkbox values passed as an argument?


So I'm wanting to run a function EVERY TIME a user clicks thebtnChangeCat button...Im having trouble and I'm really not sure how to get it to work!

Im trying to runshowCategory($_POST['chkCat'], 1)[0];and pass it the array of checked checkboxes when the user clicks thebtnChangeCat button. Im not sure why this isn't working??

I've literally searched everywhere for a WORKING solution but can't find one that will work when passing the values to a function!

    $showVideos = showCategory($categories, 1)[0];
    $rowLength = showCategory($categories, 1)[3];
    $likes = showCategory($categories, 1)[1];
    $dislikes = showCategory($categories, 1)[2];

    <div class='controller-wrap'>
        <div class='content-wrap'>
        <h3>Category: </h3>hp

            <form action='most-liked.php' method='post'>
                    $allCategories = ["All", "Sport", "Automotive", "Comedy", "Misc", "Surfing"];
                    $htmlOutput = "";
                            if($allCategories[$i] == "Surfing"){
                                $htmlOutput .= "<input selected type='checkbox' name='chkCat[]' value='".$allCategories[$i]."'/>";
                                $htmlOutput .= "<input type='checkbox' name='chkCat[]' value='".$allCategories[$i]."'/>";
                    echo $htmlOutput;

            <br />
            if(is_array($_POST['chkCat'])) {
                foreach($_POST['chkCat'] as $value){
                  echo $value;
                    $value = $_POST['chkCat'];
                    echo $value;
                // showCategory($_POST['chkCat'], 1)[0];
            // //How can I run this function with the array of CHECKBOXES??
            showCategory($_POST['chkCat'], 1)[0];
        <input type='submit' value='CHANGE CATEGORIES' class='btnlike btnLike' name='btnChangeCat'/>

People are also looking for solutions to the problem: php - Error uploading multiple images at the same time


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.