- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP How to cast variable to array?
To cast variable to array, use the below syntax −
$yourNewVariableName=(array)$yourVariableName;
The PHP code is as follows −
Example
<!DOCTYPE html> <html> <body> <?php $nameArray=Array('Mike','Sam','David'); $valueArray=(array)$nameArray; print_r($valueArray); ?> </body> </html>
Output
Array ( [0] => Mike [1] => Sam [2] => David )
- Related Articles
- How to assign a PHP variable to JavaScript?
- How to cast a list of strings to a string array?
- How to declare a global variable in PHP?
- How to convert PHP array to JavaScript array?
- How to convert Multidimensional PHP array to JavaScript array?
- How to convert array to string PHP?
- How to get a variable name as a string in PHP?
- How to work with array variable in MySQL?\n
- How to use cast() in Android sqlite?
- PHP Variable functions
- PHP Variable Basics
- PHP Variable Scope
- PHP variable Variables
- How to cast from VARCHAR to INT in MySQL?
- How to convert an array to SimpleXML in PHP?

Advertisements