- 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 display array values with text “even” to be displayed for even index values
For this, you can use for loop along with some conditions.
The PHP code is as follows −
Example
<!DOCTYPE html> <html> <body> <?php $arrayList = []; for ($counter = 0; $counter < 5; $counter++) { ($counter%2) ? ($arrayList[] = $counter) : ($arrayList[] = "Even"); } for ($counter = 0; $counter < 5; $counter++) { echo $arrayList[$counter]," "; } ?> </body> </html>
Output
Even 1 Even 3 Even
Above, for 0th index, the text “Even” is displayed and the same goes on for 2th and 4th index.
- Related Articles
- How to display array values with do while or for statement in my PHP?
- MongoDB query to display alternative documents with mapReduce() function and emit even field values
- How to find edit text values start from Number is Even or Odd?
- Fetch alternative even values from a JavaScript array?
- Matching odd even indices with values in JavaScript
- Display array structure and values in PHP 7
- Python - Filter even values from a list
- Program to delete all leaves with even values from a binary tree in Python
- How to remove null values with PHP?
- Even numbers at even index and odd numbers at odd index in C++
- How to have actual values in Matplotlib Pie Chart displayed?
- C++ program for the Array Index with same count of even or odd numbers on both sides?
- MySQL CASE WHEN with SELECT to display odd and even ids?
- Odd even index difference - JavaScript
- Even index sum in JavaScript

Advertisements