Arrays - PHP Questions and Answers
This is the questions and answers section on "PHP Arrays" with explanation for various interview, competitive examination and entrance test. Solved examples with detailed answer description, explanation are given and it would be easy to understand.
PHP’s numerically indexed array begin with position __.
Answer: Option C
Like many programming languages, the first element of an array has an index value of 0.
Which of the functions is used to sort an array in descending order?
- A. sort()
- B. asort()
- C. rsort()
- D. dsort()
Answer: Option C
sort() function is used to sort in ascending order where as rsort() meaning reverse sort is used for sorting in descending order.
Which of the following are correct ways of creating an array?
(i) state = “karnataka”;
(ii) $state = array(“karnataka”);
(iii) $state = “karnataka”;
(iv) $state = array(“karnataka”);
- A. (iii) and (iv)
- B. (ii) and (iii)
- C. Only (i)
- D. (ii), (iii) and (iv)
Answer: Option A
A variable name should start with $ symbol which is not present in i) and you need not put the square brackets when you use the array() constructor.
What will be the output of the following PHP code?
$fruits = array ("mango", "apple", "pear", "peach");
$fruits = array_flip($fruits);
Answer: Option B
As we are flipping the values, $fruits["mango"] = 0, $fruits["apple"] = 1 and so on.
What will be the output of the following php code?
$states = array("karnataka" => array
( "population" => "11,35,000", "captial" => "Bangalore"),
"Tamil Nadu" => array( "population" => "17,90,000",
"captial" => "Chennai") );
- A. karnataka 11,35,000
- B. 11,35,000
- C. population 11,35,000
- D. karnataka population
Answer: Option B
Treat states as a multidimensional array and accordingly traverse it to get the value.
Free Questions and Answers, Online Test, Mock Test - Study Online
Allindiaexams.in is a one stop destination for students, job seekers and exam aspirants. Here, you will find almost every resource for online study and online exam preparation including aptitude questions and answers with solution, reasoning questions, GK questions and answers, Placement papers, Verbal ability questions and answers, engineering questions (ECE, CSE, EEE, IT, Civil, Mechanical, Aeronautical etc.), Various interview questions and answers, Free Online Test, Mock Test, Online Quiz.
With the right online education resources, students can not only study online, but can even appear for Online Practice Tests to test their skills online. Free Online Quiz and test series are available for all the topics including Aptitude, Reasoning, GK and others.
There are two different sections for Free Online Practice Tests and Online Test. In the Online study section, free online quiz and sample tests are available for Aptitude, Reasoning, GK and all other study courses. Students can study and can appear for free tests online. In the Exam preparation section, free study material is available for all the leading competitive exams, entrance exams and recruitment exams in India. Different exam categories under exam preparation section include IT company online test, startup company written exams, automobile company online test questions and answers, Government jobs, Medical, Engineering and Management exams, Defence Exams, etc.