Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #6186

Re: How best to print an array to table?

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.php
Subject Re: How best to print an array to table?
Date 2012-05-25 16:24 +0000
Organization A noiseless patient Spider
Message-ID <jpobnb$k2j$1@dont-email.me> (permalink)
References <1i1jp7rnh4deu.11sh2s3wxhksi$.dlg@40tude.net> <8ietr7t8a6h63q4n8lmhsc7e102bumjlum@mfesser.de> <sbfbaylqzsvg.ec971qxpwbmx$.dlg@40tude.net>

Show all headers | View raw


On Thu, 24 May 2012 22:19:21 -0400, richard wrote:

> On Fri, 25 May 2012 00:51:24 +0200, Michael Fesser wrote:

>> print "<td>{$Alist['aname']}</td>";

> Does not work in this case.
> www.1littleworld.net/sample/test2.php

Perhaps you could show us the php you used, rather than link us to a 
website that only shows us the results of that php.

The code suggested will work if you type it correctly. If you don't type 
it correctly, eg miss out or change bits, it won't work.

Note for example, that:

The normal use may be $array["key"] or $array['key']

To be used inside a string delimited with "" needs the use of of '' for 
the array key:

$array['key']

the whole $array['key'] has to be enclosed in the curly brackets:

{$array['key']}

Then it can be included in a string that is enclosed in double quotes:

print "{$array['key']}";

which can also include other text:

print "<td>{$array['key']}</td>";

Which bit did you fuck up? No $ symbol? Didn't use the curly brackets? 
Put the curly brackets in the wrong places? Used the same quotes for the 
array key as the string? Got the array name or key name wrong?

Here's an example of it working:

http://www.sined.co.uk/tmp/array_print.php

Using this php (irrelevant bits snipped):

$array = array( "cold"=>"penguin" );

$content .= "<p>The value of \"{\$array['cold']}\" is: \"{$array['cold']}
\"</p>";

Rgds

Denis McMahon

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How best to print an array to table? richard <member@newsguy.com> - 2012-05-24 18:28 -0400
  Re: How best to print an array to table? Michael Fesser <netizen@gmx.de> - 2012-05-25 00:51 +0200
    Re: How best to print an array to table? richard <member@newsguy.com> - 2012-05-24 21:44 -0400
    Re: How best to print an array to table? richard <member@newsguy.com> - 2012-05-24 22:19 -0400
      Re: How best to print an array to table? Denis McMahon <denismfmcmahon@gmail.com> - 2012-05-25 16:24 +0000
  Re: How best to print an array to table? richard <member@newsguy.com> - 2012-05-24 23:27 -0400
    Re: How best to print an array to table? Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-05-25 14:09 +0000
      Re: How best to print an array to table? Denis McMahon <denismfmcmahon@gmail.com> - 2012-05-25 16:33 +0000
      Re: How best to print an array to table? Captain Paralytic <paul_lautman@yahoo.com> - 2012-05-30 04:49 -0700

csiph-web