Fun at zangOOr Click Here
2 like 0 dislike
8 views
in Education & Reference by (640 points)
$array = ("Tony","Steve","Peter","Steven","Bruce");


//1. logic to create query :

  // SELECT * FROM avengers where name in ("Tony","Steve","Peter","Steven","Bruce");

  //2. create a general function of it where we pass any array and returns the query.

2 Answers

0 like 0 dislike
by (3.3k points)
 
Best answer
$array = array("Tony","Steve","Peter","Steven","Bruce");


  function query($array){
    $str = implode("','",$array);
    $q="select * from avengers where name in ('". $str ."')";
    return $q;
  
 }
  
  echo query($array);
0 like 0 dislike
by (3.3k points)
$array = array("Tony","Steve","Peter","Steven","Bruce");

  $ar_user  = array_map( function($str){ return sprintf("\"%s\"", $str); }, $array);
  $ar_list  = implode(",",$ar_user);
  $query    = "SELECT * FROM avengers where name in (".$ar_list.")";
  echo $query;

Related questions

2 like 0 dislike
1 answer 13 views
0 like 0 dislike
1 answer 111 views
1 like 0 dislike
1 answer 3 views
1 like 0 dislike
1 answer 81 views
1 like 0 dislike
1 answer 3.4k views
0 like 0 dislike
1 answer 2.2k views
1 like 0 dislike
1 answer 1.1k views
1 like 0 dislike
1 answer 561 views
0 like 0 dislike
2 answers 963 views

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

...