|
-
Mar 11th, 2013, 11:50 AM
#2
Re: Find the last non zero value in an array
PHP Code:
<?php
$myarr = array(1,0,22,3,85,69,0,11,2,0,0); //sample array $t = array_reverse($myarr); //reverses the array foreach($t as $ele) //loop through the elements in array { if($ele > 0) //if the element is greater than 0... { echo 'Last non-zero number = ' . $ele; //gives 2 as answer break; // no need to continue the loop since we found an item! } }
?>
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|