Skip to content
Interview Shortout
  • Home
  • Articles
  • PHP
  • Python
  • Java Script
  • MySQL
  • Magento
  • Startups
  • Other

PHP array Interview question-answers

Posted on January 12, 2018 By Dhananjay No Comments on PHP array Interview question-answers
PHP

What is an array?
An array is a collection of data in a sequential manner. In PHP an array may hold many types of data.

How to define an empty array in PHP?
There are many ways to define arrays in PHP

1
2
$cars=[];
$cars=array();
How to check that a variable is an array in PHP?
There is library method to check, whether a variable is an array or not.
is_array($variable); – the function accepts a variable as a parameter and returns Boolean. If variable passed in it is an array it returns TRUE.

How to check the size of array?
We can find the size of an array using sizeof() function.

How many types of arrays are there in PHP we use?
Usually, there are three types of arrays in PHP:
1- Indexed Array
2- Associative array
3- Multidimensional Array
How can we add new value into an array in rum time?
We can do this using php method array_push(). There is another way we can simply assign new value to array and it will hold the next index. For example
1
2
3
4
5
$car=array('BMW','Benz');
$car[]='Toyota';
$car[]='Sujuki';
?>
And finalil it will print: BMW,Benz,Toyota,Sujuki.
How can we remove a value from an array in PHP?
We can remove a value from an array in php using unset() method. We have to unset the index of that value.Suppose we have to delete ‘BMW’ from above array, then we have to unset the index of ‘BMW’ and tht is 0, so It will be as :
1
2
3
unset($car[0]);
?>
Demostrate foreach loop on a PHP array.
We are assuming that we have to print the name of cars in list using foreach loop. So we can do this as given in code snippet:
1
2
3
4
5
foreach($car as $key=>$value){
    echo "This a brand new ".$value;
    echo "
"
;
}?>
What will be the output when we execute the PHP code given below?
1
2
3
4
$array=array(1,2,3,4,5,6,7,8);
echo sizeof($array);
?>
OUTPUT:
Out of the above code will be the size of array. It will be 8.
How to sort an associative array in ascending order, according to the value?
We can use PHP library function asort(). This will sort the array in ascending order. In descending order, we will use arsort(). These functions return sorted arrays.
What is the function that we can use to remove the duplicate valuse from array in PHP?
PHP has array_unique() function to remove the duplicate values from array.
1
2
3
4
5
6
$fruits=array("a"=>"mangow","b"=>"orange","c"=>"apple","d"=>"mangow");
print_r(array_unique($fruits));
?>
?>
We aill get a list of uniq values.
How we can find an array of keys of another associative array?
Pass an associative array in function array_keys() and this will return an array of keys.

Post navigation

Next Post: WordPress Basic Interview Questions and Answers ❯

Leave a Reply Cancel reply

You must be logged in to post a comment.

Doglapan

Recent Posts

  • Captable for Startups?
  • What is chat GPT?
  • All about Indexing in MySQL
  • Exploring the Growth and Future of Fintech Companies in Indian Startup Culture
  • Angel Investors in the Indian Startup Ecosystem: Understanding their Characteristics, Benefits and Role

Popular

AJAX artificial intelligence CakePHP Career Certifications CodeIgniter COVID Database Data Science DBMS DevOps Django Drupal ES6 Google Analytics HR Internship Interview Java Script jQuery Magento MVC MySQL PHP reactjs Risk Management Startups Training Visual Basic

Categories

  • AJAX
  • AJAX Interview Questions
  • Android
  • Articles
  • Artificial Intelligence
  • Banking
  • Big Data
  • Cake PHP Interview Questions
  • CakePHP
  • Career Guide
  • Certifications
  • CI/CD
  • Codeigniter Interview Questions
  • Codeigniter4
  • CSS
  • Data Science
  • DBMS
  • DevOps
  • Drupal
  • ES6 Interview Questions
  • Fresher Interview
  • Google Analytics
  • Gov Job
  • HR Interview
  • HTML
  • Internship
  • Interview
  • Java Script
  • jQuery
  • jQuery Interview Questions
  • JSON
  • Magento
  • MVC
  • MySQL
  • MySQL Interview Questions
  • OOPS
  • PHP
  • PHP Interview Questions
  • Python
  • Python Interview Questions
  • Reactjs Interview Questions
  • Resume
  • SEO
  • Startups
  • Visual Basic
  • WordPress
  • Wordpress Tutorial

Resources

  • Home
  • Paid Guest Post
  • About
  • Contact
  • Privacy Policy
  • DCMA
  • Home
  • Paid Guest Post
  • About
  • Contact
  • Privacy Policy
  • DCMA

Copyright © 2023 Interview Shortout.

Theme: Oceanly by ScriptsTown

Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}