Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-28-2010, 09:13 AM Count w/2 & 3d array
Extreme Talker

Posts: 173
Trades: 0
I want to count the number of values in one direction of a 2 and 3 day array.
Is
PHP Code:
count($po[x]) 
an exceptable form of $po[x][y]

PHP Code:
$a=0;
$b=0;
$i=0;
for(
$x=0;$x<=count($po[$x]);$x++){
 for(
$y=0;$y<=count($milestone[$x][$y]);$y++){
  
$i++;
  echo
'<tr class=d'.($i 1).'>';
   if(empty(
$y)){ //prints PO details on first row
       
echo'<td>'.$po[$x][$a++].'</td>'.        //PO number
        
'<td>'.$po[$x][$a++].'</td>'.        //PO date
        
'<td>'.number_format($po[$x][$a++], 2'.'',').'</td>'//PO value
        
'<td>'.$po[$x][$a++].'</td>';        //Currency
   
}
   else{  
//prints blank cells on duplicate row
        
echo'<td></td>'.
         
'<td></td>'.
         
'<td></td>'.
         
'<td></td>';
   }
   echo
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Index
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Description
    
'<td>'.number_format($milestone[$x][$y][$b++], 2'.'',').'</td>'//percentage
       
'<td>'.number_format($milestone[$x][$y][$b++], 2'.'',').'</td>'//value
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Baseline
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Estimate
       
'<td>'.$milestone[$x][$y][$b++].'</td>'.        //Actual
        
'</tr>';   
  
$b=0;
 }

I am getting the following errors and cannot see the the problem.

Quote:
Total Project Value: 0.00Purchase OrderDateValueCurrencyMilestoneDescriptionPercentageValueBaselineEstimatedActual
Notice: Undefined variable: po in C:\Program Files\EasyPHP 3.0\www\My Websites\Fat Cat\display_commercial_details.php on line 95

Notice: Undefined variable: milestone in C:\Program Files\EasyPHP 3.0\www\My Websites\Fat Cat\display_commercial_details.php on line 96

Notice: Undefined variable: po in C:\Program Files\EasyPHP 3.0\www\My Websites\Fat Cat\display_commercial_details.php on line 100
dgkindy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-29-2010, 06:37 AM Re: Count w/2 & 3d array
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
3d array !!

You sure you need that depth?
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 04-29-2010, 07:30 AM Re: Count w/2 & 3d array
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by dgkindy View Post
I am getting the following errors and cannot see the the problem.
You're getting those errors because the variables $po and $milestone are not getting initialized. As far as counting in a particular 'direction', assuming you visualize the array as a cube:
PHP Code:
$height count($milestone);
$width count($milestone[$x]);
$depth count($milestone[$x][$y]); 
Keep in mind that the width is dependent on the row and the depth is dependent on the row and column.

Quote:
Originally Posted by davidj View Post
3d array !!

You sure you need that depth?
I've found it necessary a few times. I don't know exactly what the OP is doing so I can't comment on whether it is a good approach, but sometimes the situation calls for it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-29-2010 at 07:32 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-29-2010, 07:40 AM Re: Count w/2 & 3d array
Extreme Talker

Posts: 181
Name: David Jackson
Trades: 0
I must admit I have done it before but now tend to re-evaluate my logic if I see one on the horizon. Up to now I have always found a more elegant solution.
__________________

Please login or register to view this content. Registration is FREE
davidj is offline
Reply With Quote
View Public Profile
 
Old 04-29-2010, 10:44 AM Re: Count w/2 & 3d array
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Quote:
Originally Posted by NullPointer View Post
You're getting those errors because the variables $po and $milestone are not getting initialized...
Right-o.
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Count w/2 & 3d array
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22438 seconds with 12 queries