Fun at zangOOr Click Here
2 like 0 dislike
103 views
$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.
in Education & Reference by (640 points) | 103 views

2 Answers

0 like 0 dislike
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);
by (3.3k points)
0 like 0 dislike
$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;
by (3.3k points)

Related questions

2 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Aug 2, 2018 in Education & Reference by Sam (1.4k points) | 129 views
1 like 0 dislike
1 answer
asked Jun 17 in Education & Reference by Simmi (640 points) | 101 views
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
2 answers

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

1,245 questions
1,400 answers
565 comments
4,809 users