473,513 Members | 3,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to print a row from 2d array?

6 New Member
i want to print 1,3,5 rows from 2d array. Can i use some kind of implode or loop?

$array = array(
array(11,12,13,14,15,16),
array(21,22,23,24,25,26),
array(31,32,33,34,35,36),
array(41,42,43,44,45,46),
array(51,52,53,54,55,56),
array(61,62,63,64,65,66)
);

I want it to look like this: "array row1: 11,12,13,14,15,16"
Nov 18 '15 #1
1 1478
Niheel
2,456 Recognized Expert Moderator Top Contributor
Comments in the code explain the process
Expand|Select|Wrap|Line Numbers
  1. foreach($array as $i=>$array_values){
  2.  
  3.     // check for the rows you want and subtract 1 since
  4.     // array counts start at 0    
  5.       if($i == 0 || $i == 2 || $i == 4){
  6.  
  7.           // turn array into a string split with commas
  8.         $array_values = implode(",",$array_values);
  9.         // add + 1 to array index $i to display the right row number
  10.         $row_num = $i + 1;
  11.         // output ddesired results
  12.         echo "row". $row_num ." ".$array_values."<br/>"; 
  13.  
  14.     }  
  15. }
  16.  
Nov 18 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2145
by: praba kar | last post by:
Dear all, In Php array_slice function base we can print array contents as per our desire eg) $a = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); $arr = array_slice($a,10,10); this function will print 11,12,13,14,15
4
2516
by: Shailesh | last post by:
Hi! I want to overload << operator so that it can print an arry defined in MyClass.My problem is that I want to print only a no of elements NOT all the elements in the array and this no of elements depends upon user input.The code below describes this in detail: class MyClass { public: unsigned short x;
1
1513
by: Ellen Manning | last post by:
The main report shows all medical conferences for a resident by year, by month. A resident can attend many of the same conferences in a year. In the year footer, I have a subreport that summarizes all conferences and the number of times attended. This data is stored in an array that is updated during the printing of the report detail. I...
12
2660
by: joestevens232 | last post by:
Hello, I'm having a little problem with my code...I have the program written but its just not doing what I want and needs a minor tweak and I've been trying to fix it for ohurs and can't find a solution. I just need to write a function that removes the duplicates in an array. heres my code for main #include <iostream> #include "accfuncs.cpp"...
9
1882
by: JackpipE | last post by:
I need to create multidimensional array with arrays inside of it. database name | value1 | value2 john | red | 45 john | red | 56 john | yellow | 11 mike | blue | 23 mike | black | 41
2
1406
by: kriz4321 | last post by:
Hi I have a array in which I need to count the number of ocurrence of a particular word for eg I need to count no of times a word "test" , "test2" occurs in a array @list. (The contents of the array is around 100 lines) Code: open(FH3, "sample.txt"); while(<FH3>)
3
1995
by: Brian Smither | last post by:
$result = $class->method(); //returns an array of associative arrays if($result==TRUE) $cat=$result; I've been converting a class from an original and the original class *apparently* returned an array that could be boolean tested. My conversion seems to have lost this ability. if($result) seems to be testing for non-NULL which gets me...
2
2490
by: Karthik Prasath | last post by:
after finishing my problem given by my head and the values are stored in the array and i want to print that in a applet window.. how can i proceed? help me with sample program advance thanks for you looking forward for your reply
2
1850
by: Kalpesh Katwala | last post by:
I'm trying to read in a data file into an array. And split it into lines. I've a for loop which will parse the array, split the line (on ",") and execute another command. Here is the code. Problem is that PERL will parse only the last 11 lines from the data file. open TestList, "Testlist.dat" or die "Cannot open file to read data\n";...
2
3825
by: chintan85 | last post by:
Hi Guys, Any suggestion would be very helpful on this. My codes goes likes this while(@row = $sql_query->fetchrow_array()) { print $row; )
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5701
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.