Jump to content

[SOLVED] Echoing an array.... Argh


suttercain

Recommended Posts

I got this to work many times before but I can't figure out why it's not working this time. I am pulling a column from MySQL named 'manuf' and I am assigning values to the keys and I want to echo the value.

 

<?php
$makes = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE',
		   'FERI'=>'FERARAI',
		   'FORD'=>'FORD',
		   'GMC'=>'GMC',
		   'HOND'=>'HONDA',
		   'HUMM'=>'HUMMER',
		   'HYND'=>'HYUNDAI',
		   'INFI'=>'INFINITI',
		   'ISUZ'=>'ISUZU',
		   'JAG'=>'JAGUAR',
		   'JEEP'=>'JEEP',
		   'KI'=>'KIA',
		   'LAMB'=>'LABORGHINI',
		   'LAND'=>'LAND ROVER',
		   'LEXS'=>'LEXUS',
		   'LINC'=>'LINCOLN',
		   'LOTU'=>'LOTUS',
		   'MASE'=>'MASERATI',
		   'MAZD'=>'MAZDA',
		   'MBZ'=>'MERCEDES BENZ',
		   'MINI'=>'MINI',
		   'MITS'=>'MITSUBISHI',
		   'MORG'=>'MORGAN',
		   'MRCY'=>'MERCURY',
		   'NISS'=>'NISSAN',
		   'PONT'=>'PONTIAC',
		   'PORS'=>'PORSCHE',
		   'RPP'=>'ROUSCH',
		   'RR'=>'ROLLS ROYCE',
		   'SAAB'=>'SAAB',
		   'SALE'=>'SALEEN',
		   'SATU'=>'SATURN',
		   'SHLB'=>'SHELBY',
		   'SUBA'=>'SUBARU',
		   'SUZU'=>'SUZUKI',
		   'TOTA'=>'TOYOTA',
		   'VOLK'=>'VOLKSWAGEN',
		   'VOLV'=>'VOLVO',
		   );		   
print $makes['manuf'];

echo "<center>$makes[manuf]</center>";
?>

 

 

Where am I going wrong? Thanks in advance for your help.

 

Shannon

Link to comment
Share on other sites

Hi Frost, I gave this a try and the result is blank.

 

<?php
$manuf = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE',
		   'FERI'=>'FERARAI',
		   'FORD'=>'FORD',
		   'GMC'=>'GMC',
		   'HOND'=>'HONDA',
		   'HUMM'=>'HUMMER',
		   'HYND'=>'HYUNDAI',
		   'INFI'=>'INFINITI',
		   'ISUZ'=>'ISUZU',
		   'JAG'=>'JAGUAR',
		   'JEEP'=>'JEEP',
		   'KI'=>'KIA',
		   'LAMB'=>'LABORGHINI',
		   'LAND'=>'LAND ROVER',
		   'LEXS'=>'LEXUS',
		   'LINC'=>'LINCOLN',
		   'LOTU'=>'LOTUS',
		   'MASE'=>'MASERATI',
		   'MAZD'=>'MAZDA',
		   'MBZ'=>'MERCEDES BENZ',
		   'MINI'=>'MINI',
		   'MITS'=>'MITSUBISHI',
		   'MORG'=>'MORGAN',
		   'MRCY'=>'MERCURY',
		   'NISS'=>'NISSAN',
		   'PONT'=>'PONTIAC',
		   'PORS'=>'PORSCHE',
		   'RPP'=>'ROUSCH',
		   'RR'=>'ROLLS ROYCE',
		   'SAAB'=>'SAAB',
		   'SALE'=>'SALEEN',
		   'SATU'=>'SATURN',
		   'SHLB'=>'SHELBY',
		   'SUBA'=>'SUBARU',
		   'SUZU'=>'SUZUKI',
		   'TOTA'=>'TOYOTA',
		   'VOLK'=>'VOLKSWAGEN',
		   'VOLV'=>'VOLVO',
		   );		   
print $makes[$manuf];

echo "<center>$makes[$manuf]</center>";	 
?>

Link to comment
Share on other sites

Wow what are you trying to do, now the array is named $manuf instead of makes???

 

Maybe reading up on arrays via http://www.php.net/array will do you some good?

 

<?php
// do not change this it is fine.
$makes = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE',
		   'FERI'=>'FERARAI',
		   'FORD'=>'FORD',
		   'GMC'=>'GMC',
		   'HOND'=>'HONDA',
		   'HUMM'=>'HUMMER',
		   'HYND'=>'HYUNDAI',
		   'INFI'=>'INFINITI',
		   'ISUZ'=>'ISUZU',
		   'JAG'=>'JAGUAR',
		   'JEEP'=>'JEEP',
		   'KI'=>'KIA',
		   'LAMB'=>'LABORGHINI',
		   'LAND'=>'LAND ROVER',
		   'LEXS'=>'LEXUS',
		   'LINC'=>'LINCOLN',
		   'LOTU'=>'LOTUS',
		   'MASE'=>'MASERATI',
		   'MAZD'=>'MAZDA',
		   'MBZ'=>'MERCEDES BENZ',
		   'MINI'=>'MINI',
		   'MITS'=>'MITSUBISHI',
		   'MORG'=>'MORGAN',
		   'MRCY'=>'MERCURY',
		   'NISS'=>'NISSAN',
		   'PONT'=>'PONTIAC',
		   'PORS'=>'PORSCHE',
		   'RPP'=>'ROUSCH',
		   'RR'=>'ROLLS ROYCE',
		   'SAAB'=>'SAAB',
		   'SALE'=>'SALEEN',
		   'SATU'=>'SATURN',
		   'SHLB'=>'SHELBY',
		   'SUBA'=>'SUBARU',
		   'SUZU'=>'SUZUKI',
		   'TOTA'=>'TOYOTA',
		   'VOLK'=>'VOLKSWAGEN',
		   'VOLV'=>'VOLVO');		   

// Somewhere $manuf needs to be set for testing purposes I will set it right now
$manuf = 'SUBA';
print $makes[$manuf]; // should print "SUBARU";

// or it could be done like this:
print $makes['TOTA']; // should print "TOTA";

// Just as long as the INDEX/KEY ('TOTA') of the ARRAY ($makes) is in the array it will print something.

echo "<center>".$makes[$manuf]."</center>"; // personal preference I like to break it up 
?>

 

Just an fyi Arrays work like this:

 

$array[$key] = $value;

meaning the array at index key contains $value.

 

Link to comment
Share on other sites

I got this to work many times before but I can't figure out why it's not working this time. I am pulling a column from MySQL named 'manuf' and I am assigning values to the keys and I want to echo the value.

 

<?php
$makes = array('ACUR'=>'ACURA', 
		   'ALP'=>'ALPINA', 
		   'ASMA'=>'ASTON MARTIN LAGONDA',
		   'AUDI'=>'AUDI',
		   'BAF'=>'FORD BAF CNG',
		   'BAYT'=>'GENERAL MOTORS BAYTECH CNG',
		   'BENT'=>'BENTLY',
		   'BMW'=>'BMW',
		   'BUIC'=>'BUICK',
		   'CAD'=>'CADILLAC',
		   'CHEV'=>'CHEVROLET',
		   'CHRS'=>'CHRYSLER',
		   'CUMM'=>'CUMMINS',
		   'DODG'=>'DODGE',
		   'FERI'=>'FERARAI',
		   'FORD'=>'FORD',
		   'GMC'=>'GMC',
		   'HOND'=>'HONDA',
		   'HUMM'=>'HUMMER',
		   'HYND'=>'HYUNDAI',
		   'INFI'=>'INFINITI',
		   'ISUZ'=>'ISUZU',
		   'JAG'=>'JAGUAR',
		   'JEEP'=>'JEEP',
		   'KI'=>'KIA',
		   'LAMB'=>'LABORGHINI',
		   'LAND'=>'LAND ROVER',
		   'LEXS'=>'LEXUS',
		   'LINC'=>'LINCOLN',
		   'LOTU'=>'LOTUS',
		   'MASE'=>'MASERATI',
		   'MAZD'=>'MAZDA',
		   'MBZ'=>'MERCEDES BENZ',
		   'MINI'=>'MINI',
		   'MITS'=>'MITSUBISHI',
		   'MORG'=>'MORGAN',
		   'MRCY'=>'MERCURY',
		   'NISS'=>'NISSAN',
		   'PONT'=>'PONTIAC',
		   'PORS'=>'PORSCHE',
		   'RPP'=>'ROUSCH',
		   'RR'=>'ROLLS ROYCE',
		   'SAAB'=>'SAAB',
		   'SALE'=>'SALEEN',
		   'SATU'=>'SATURN',
		   'SHLB'=>'SHELBY',
		   'SUBA'=>'SUBARU',
		   'SUZU'=>'SUZUKI',
		   'TOTA'=>'TOYOTA',
		   'VOLK'=>'VOLKSWAGEN',
		   'VOLV'=>'VOLVO',
		   );		   
print $makes['manuf'];

echo "<center>$makes[manuf]</center>";
?>

 

 

Where am I going wrong? Thanks in advance for your help.

 

Shannon

 

nothing is wrong with it.. but you don't have an array element with the key "manuf".. so it's returning nothing.

 

if you want to see what's in the array use

print_r($makes);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.