PHP:我们如何创建一个联合的数字关联数组; 我如何自己查找索引?

Here's the generic workaround I am using:

http://codepad.viper-7.com/2tiPvN


$j=0;
$paper = array('copier' => "Copier and Multipurpose",
               'inkjet' => "Injet Printer",
               'laser' => "Laser Printer",
               'photo' => "Photo Paper");

foreach ($paper as $index => $description)
{
  echo "$j, $index: $description
"; $j++; }

I want to have numeric identifiers and keyword identifiers.

Meanwhile, because foreach ($paper as $description) gives the description and

foreach ($paper as $index => $description) 

gives the index and then the description..., is there a way to just get the index in a foreach, without having to specify a variable for the description?

not sure what you mean, but maybe

foreach(array_keys($ary) as $key)...

Yes, with array_keys():

$indexes = array_keys($paper);

See: http://php.net/function.array-keys

foreach ($paper as $key => $description) { ... }

is the syntax to get both key and value in the loop.

As for keying the array with both numeric and textual values, PHP's arrays don't really support that. But nothing says you can't duplicate the values internally:

$array = (
   0 => 'Copier and ...',
   'copier' => 'Copier and ...'
   ...
);

Note that with this version, foreach will return both versions. You'd have to do a regular for ($i = 0; .....) { } loop to catch only the numeric keys.

foreach(array_keys($ary) as $key)... its give index

array['0']=>'copier'
array['1']=> 'inkjet'
          array['2']=>     'laser' 
               array['3']=>'photo' 
similarly for values
foreach(array_values($ary) as $value)...