Forum Moderators: coopster
I need to print the entire contents of my array. I don't want it looped... I simply want my array:
$my_array = array("I", "am", "obviously", "dumb", "!")
to print like:
Iamobviouslydumb!
All I can come up with are loops that call to each variable, or the print_r method, which puts the [1], [0] and so-on in the readable text. I thought it would be as simple as:
echo "$my_array"; or
echo "$my_array[ ]"; or
echo "$my_array[]";
Nope, all I come up with when I do that is "Array". Like I said, I feel REALLY stupid, and my feelings are crushed right about now! I'm going to go crawl under my desk now, I'll check back here in an hour. I appreciate your input...
-- Zak
foreach ($my_array as $key => $val) echo $val;
While we're asking stupid array questions ... :D
How can I easily obtain the number of array 'rows' that contain the same data. Ex:
$my_array = array($_ORDNUM , $_CUSTID , $_ITEMID);
$_ORDNUM will be repeated for each item I'm checking. I need to know how many of $_ORDNUM there are in this array.
For the life of me it seems so simple, but there's daylight all around me now... can't think (too) and I should be sleeping.
echo join("", array_values($my_array));
for the second question, I assume you are talking about a multi-dimensional array? I can't see any way that you can do it without looping through the array, but it rather depends on where this is built from - you presumably pull it out of a database or flat file or something of the sort? If so, you are probably best building a supplementary array keyed on the value you want to count at the same time.
edit: just beaten to it... if you have a flat array then the previous poster is of course right that you don't need array_values but if you specify keys then you will I think.
It is a multi-dimensional array, and looping thru the array is out, since I'm looping thru it already in the processing. I thought about a supplemental array.. then I thought (since I've installed PHP and MySQL on this machine) just INPUT my data to a table - which may come in handy down the road.
It just adds another layer of sauce to the code. Hmmm, maybe even a meatball. But.. I can get the number of rows from that table pretty quick.