LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-29-2005, 04:26 PM   #1
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Rep: Reputation: 61
PHP Help... PLZ!


Why do I keep getting this error: ?

Fatal error: Cannot use string offset as an array in /var/www/files/transcode.ca/wh33t/surveytool/surveyresults.php on line 34

I'm trying to use... I'm not even sure what they are called. But its when you use the second field of the array. I'm probably not even doing this right. Basically I have an array, and the first column (if thats what they are called) $array[firstcolumn] contains 27 records and many of them are the same. I am trying to write a script that finds out how many different records there are. So in this case there is only three differences, Central, South End or North End. So I want my script to count how many of each. So what I'm trying to do is a foreach loop. Observe:

Code:
   foreach($array as $values)
      {
      if(isset($values[$a]))
         {
         $values[$a][amount]++;
         } else {
         $values[$a][amount]=1;
         }
      $a++;
      }
So I'm trying to make the second field hold the amount of times the value Central or North end etc... appears.. Am I going about this totally wrong and wtf is up with that error message?
 
Old 06-29-2005, 04:44 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I think you want to use array_key_exists and not isset.
 
Old 06-29-2005, 04:52 PM   #3
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
excellent. Ill try that.
 
Old 06-29-2005, 05:21 PM   #4
wh33t
Member
 
Registered: Oct 2003
Location: Canada
Posts: 922

Original Poster
Rep: Reputation: 61
nah that doesn't work either. Its still giving me that error message.
 
Old 06-30-2005, 10:17 AM   #5
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 33
PHP Code:
$blah['south'] = array(1,2,3,4,5);
$blah['central'] = array(1,2,3);
$blah['north'] = array(1,2,3,4);
$c="";

foreach(
$blah as $key => $value){
    
$c .= $key "  = " count($blah[$key]) . "\n";
}

echo 
$c
result should be something like

south = 5
central = 3
north = 4

i think!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP & Apache Issue? Plz help! wh33t Programming 1 10-01-2005 05:17 AM
plz plz help me regarding route mapping nedian123 Programming 1 07-13-2004 08:17 AM
plz plz solve my route mapping problem nedian123 Linux - Networking 1 07-12-2004 09:41 PM
PHP RPM 4 RH9 - Someone Plz Help..... afoote Linux - General 1 05-10-2004 11:41 AM
PHP / MySQL problems, plz help! TIA! jerome187 Linux - Software 6 04-01-2003 03:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration