Re: [PHP] Arrays

2013-02-26 Thread tamouse mailing lists
On Mon, Feb 25, 2013 at 9:51 PM, Karl DeSaulniers k...@designdrumm.com wrote:
 Never mind. I found a different function that reads out the children as well
 into the array.


 function xml_parse_into_assoc($data) {
   $p = xml_parser_create();

   xml_parser_set_option($p, XML_OPTION_CASE_FOLDING,
 0);
   xml_parser_set_option($p, XML_OPTION_SKIP_WHITE,
 1);

   xml_parse_into_struct($p, $data, $vals, $index);
   xml_parser_free($p);

   $levels = array(null);

   foreach ($vals as $val) {
 if ($val['type'] == 'open' || $val['type'] ==
 'complete') {
   if (!array_key_exists($val['level'], $levels))
 {
 $levels[$val['level']] = array();
   }
 }

 $prevLevel = $levels[$val['level'] - 1];
 $parent = $prevLevel[sizeof($prevLevel)-1];

 if ($val['type'] == 'open') {
   $val['children'] = array();
   array_push($levels[$val['level']], $val);
   continue;
 }

 else if ($val['type'] == 'complete') {
   $parent['children'][$val['tag']] =
 $val['value'];
 }

 else if ($val['type'] == 'close') {
   $pop = array_pop($levels[$val['level']]);
   $tag = $pop['tag'];

   if ($parent) {
 if (!array_key_exists($tag,
 $parent['children'])) {
   $parent['children'][$tag] =
 $pop['children'];
 }
 else if
 (is_array($parent['children'][$tag])) {
 if(!isset($parent['children'][$tag][0]))
 {
 $oldSingle =
 $parent['children'][$tag];
 $parent['children'][$tag] = null;
 $parent['children'][$tag][] =
 $oldSingle;

 }
   $parent['children'][$tag][] =
 $pop['children'];
 }
   }
   else {
 return(array($pop['tag'] =
 $pop['children']));
   }
 }

 $prevLevel[sizeof($prevLevel)-1] = $parent;
   }
 }


 $params = xml_parse_into_assoc($result);//$result =
 xml result from USPS api

 Original function by: jemptymethod at gmail dot com
 Duplicate names fix by: Anonymous (comment right above original function)

 Best,
 Karl



 On Feb 25, 2013, at 7:50 PM, Jim Lucas wrote:

 On 02/25/2013 05:40 PM, Karl DeSaulniers wrote:

 Hi Guys/Gals,
 If I have an multidimensional array and it has items that have the same
 name in it, how do I get the values of each similar item?

 EG:

 specialservices = array(
 specialservice = array(
 serviceid = 1,
 servicename= signature required,
 price = $4.95
 ),
 secialservice = array(
 serviceid = 15,
 servicename = return receipt,
 price = $2.30
 )
 )

 How do I get the prices for each? What would be the best way to do this?
 Can I utilize the serviceid to do this somehow?
 It is always going to be different per specialservice.

 TIA,

 Best,

 Karl DeSaulniers
 Design Drumm
 http://designdrumm.com



 This will never work.  Your last array will always overwrite your previous
 array.

 Here is how I would suggest building it:


 $items = array(
1 = array(
serviceid = 1,
servicename= signature required,
price = $4.95
),
15 = array(
serviceid = 15,
servicename = return receipt,
price = $2.30
)
 )

 This will ensure that your first level indexes never overwrite themselves.

 But, with that change made, then do this:

 foreach ( $items AS $item ) {
  if ( array_key_exists('price', $item) ) {
echo $item['price'];
  } else {
echo 'Item does not have a price set';
  }
 }

 Resources:
 http://php.net/foreach
 http://php.net/array_key_exists

 --
 Jim Lucas

 http://www.cmsws.com/
 http://www.cmsws.com/examples/


 Karl DeSaulniers
 Design Drumm
 http://designdrumm.com


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Would this work for you?
http://us.php.net/manual/en/function.xml-parse-into-struct.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, 

Re: [PHP] Arrays

2013-02-26 Thread Karl DeSaulniers


On Feb 26, 2013, at 10:35 PM, tamouse mailing lists wrote:

On Mon, Feb 25, 2013 at 9:51 PM, Karl DeSaulniers k...@designdrumm.com 
 wrote:
Never mind. I found a different function that reads out the  
children as well

into the array.


   function xml_parse_into_assoc($data) {
 $p = xml_parser_create();

 xml_parser_set_option($p,  
XML_OPTION_CASE_FOLDING,

0);
 xml_parser_set_option($p,  
XML_OPTION_SKIP_WHITE,

1);

 xml_parse_into_struct($p, $data, $vals,  
$index);

 xml_parser_free($p);

 $levels = array(null);

 foreach ($vals as $val) {
   if ($val['type'] == 'open' ||  
$val['type'] ==

'complete') {
 if (!array_key_exists($val['level'],  
$levels))

{
   $levels[$val['level']] = array();
 }
   }

   $prevLevel = $levels[$val['level'] - 1];
   $parent =  
$prevLevel[sizeof($prevLevel)-1];


   if ($val['type'] == 'open') {
 $val['children'] = array();
 array_push($levels[$val['level']],  
$val);

 continue;
   }

   else if ($val['type'] == 'complete') {
 $parent['children'][$val['tag']] =
$val['value'];
   }

   else if ($val['type'] == 'close') {
 $pop =  
array_pop($levels[$val['level']]);

 $tag = $pop['tag'];

 if ($parent) {
   if (!array_key_exists($tag,
$parent['children'])) {
 $parent['children'][$tag] =
$pop['children'];
   }
   else if
(is_array($parent['children'][$tag])) {
   if(!isset($parent['children'] 
[$tag][0]))

{
   $oldSingle =
$parent['children'][$tag];
   $parent['children'][$tag] =  
null;

   $parent['children'][$tag][] =
$oldSingle;

   }
 $parent['children'][$tag][] =
$pop['children'];
   }
 }
 else {
   return(array($pop['tag'] =
$pop['children']));
 }
   }

   $prevLevel[sizeof($prevLevel)-1] =  
$parent;

 }
   }


   $params = xml_parse_into_assoc($result);// 
$result =

xml result from USPS api

Original function by: jemptymethod at gmail dot com
Duplicate names fix by: Anonymous (comment right above original  
function)


Best,
Karl



On Feb 25, 2013, at 7:50 PM, Jim Lucas wrote:


On 02/25/2013 05:40 PM, Karl DeSaulniers wrote:


Hi Guys/Gals,
If I have an multidimensional array and it has items that have  
the same

name in it, how do I get the values of each similar item?

EG:

specialservices = array(
specialservice = array(
serviceid = 1,
servicename= signature required,
price = $4.95
),
secialservice = array(
serviceid = 15,
servicename = return receipt,
price = $2.30
)
)

How do I get the prices for each? What would be the best way to  
do this?

Can I utilize the serviceid to do this somehow?
It is always going to be different per specialservice.

TIA,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




This will never work.  Your last array will always overwrite your  
previous

array.

Here is how I would suggest building it:


$items = array(
  1 = array(
  serviceid = 1,
  servicename= signature required,
  price = $4.95
  ),
  15 = array(
  serviceid = 15,
  servicename = return receipt,
  price = $2.30
  )
)

This will ensure that your first level indexes never overwrite  
themselves.


But, with that change made, then do this:

foreach ( $items AS $item ) {
if ( array_key_exists('price', $item) ) {
  echo $item['price'];
} else {
  echo 'Item does not have a price set';
}
}

Resources:
http://php.net/foreach
http://php.net/array_key_exists

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/



Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Would this work for you?
http://us.php.net/manual/en/function.xml-parse-into-struct.php



That is where I got this function. :)
Comment 12 and 13 on that page.
Yes it worked for me.

Best,

Karl DeSaulniers
Design Drumm

Re: [PHP] Arrays

2013-02-25 Thread Adam Richardson
On Mon, Feb 25, 2013 at 8:40 PM, Karl DeSaulniers k...@designdrumm.com wrote:
 Hi Guys/Gals,
 If I have an multidimensional array and it has items that have the same name
 in it, how do I get the values of each similar item?

 EG:

 specialservices = array(
 specialservice = array(
 serviceid = 1,
 servicename= signature required,
 price = $4.95
 ),
 secialservice = array(
 serviceid = 15,
 servicename = return receipt,
 price = $2.30
 )
 )

 How do I get the prices for each? What would be the best way to do this?
 Can I utilize the serviceid to do this somehow?
 It is always going to be different per specialservice.

Something appears to be amiss, as your array couldn't contain multiple
items with the specialservice key (I'm assuming the second key
'secialservice' is just a typo), as any subsequent assignments would
overwrite the previous value.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2013-02-25 Thread Jim Lucas

On 02/25/2013 05:40 PM, Karl DeSaulniers wrote:

Hi Guys/Gals,
If I have an multidimensional array and it has items that have the same
name in it, how do I get the values of each similar item?

EG:

specialservices = array(
specialservice = array(
serviceid = 1,
servicename= signature required,
price = $4.95
),
secialservice = array(
serviceid = 15,
servicename = return receipt,
price = $2.30
)
)

How do I get the prices for each? What would be the best way to do this?
Can I utilize the serviceid to do this somehow?
It is always going to be different per specialservice.

TIA,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




This will never work.  Your last array will always overwrite your 
previous array.


Here is how I would suggest building it:


$items = array(
1 = array(
serviceid = 1,
servicename= signature required,
price = $4.95
),
15 = array(
serviceid = 15,
servicename = return receipt,
price = $2.30
)
)

This will ensure that your first level indexes never overwrite themselves.

But, with that change made, then do this:

foreach ( $items AS $item ) {
  if ( array_key_exists('price', $item) ) {
echo $item['price'];
  } else {
echo 'Item does not have a price set';
  }
}

Resources:
http://php.net/foreach
http://php.net/array_key_exists

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2013-02-25 Thread Karl DeSaulniers


On Feb 25, 2013, at 7:48 PM, Adam Richardson wrote:

On Mon, Feb 25, 2013 at 8:40 PM, Karl DeSaulniers k...@designdrumm.com 
 wrote:

Hi Guys/Gals,
If I have an multidimensional array and it has items that have the  
same name

in it, how do I get the values of each similar item?

EG:

specialservices = array(
   specialservice = array(
   serviceid = 1,
   servicename= signature required,
   price = $4.95
   ),
   secialservice = array(
   serviceid = 15,
   servicename = return receipt,
   price = $2.30
   )
)

How do I get the prices for each? What would be the best way to do  
this?

Can I utilize the serviceid to do this somehow?
It is always going to be different per specialservice.


Something appears to be amiss, as your array couldn't contain multiple
items with the specialservice key (I'm assuming the second key
'secialservice' is just a typo), as any subsequent assignments would
overwrite the previous value.

Adam

--
Nephtali:  A simple, flexible, fast, and security-focused PHP  
framework

http://nephtaliproject.com



Hi Adam,
Actually you are correct. Sorry to confuse.
Its an XML response  from the USPS api I am going through, which I am  
converting to an array.


Here is the response that I am trying to convert to a multidimensional  
array.


?xml version=1.0?
RateV4ResponsePackage ID=1STZipOrigination75287/ 
ZipOriginationZipDestination87109/ZipDestinationPounds70/ 
PoundsOunces0/OuncesContainerRECTANGULAR/ 
ContainerSizeLARGE/SizeWidth2/WidthLength15/ 
LengthHeight10/HeightZone4/ZonePostage  
CLASSID=1MailServicePriority Maillt;supgt;amp;reg;lt;/ 
supgt;/MailServiceRate62.95/ 
RateSpecialServicesSpecialServiceServiceID1/ 
ServiceIDServiceNameInsurance/ServiceNameAvailabletrue/ 
AvailableAvailableOnlinetrue/AvailableOnlinePrice1.95/ 
PricePriceOnline1.95/PriceOnlineDeclaredValueRequiredtrue/ 
DeclaredValueRequiredDueSenderRequiredfalse/DueSenderRequired/ 
SpecialServiceSpecialServiceServiceID0/ 
ServiceIDServiceNameCertified Maillt;supgt;amp;reg;lt;/supgt;/ 
ServiceNameAvailabletrue/AvailableAvailableOnlinefalse/ 
AvailableOnlinePrice3.10/PricePriceOnline0/PriceOnline/ 
SpecialServiceSpecialServiceServiceID19/ 
ServiceIDServiceNameAdult Signature Required/ 
ServiceNameAvailablefalse/AvailableAvailableOnlinetrue/ 
AvailableOnlinePrice0/PricePriceOnline4.95/PriceOnline/ 
SpecialService/SpecialServices/Postage/PackagePackage  
ID=2NDZipOrigination75287/ZipOriginationZipDestination87109/ 
ZipDestinationPounds55/PoundsOunces0/ 
OuncesContainerRECTANGULAR/ContainerSizeLARGE/SizeWidth2/ 
WidthLength15/LengthHeight10/HeightZone4/ZonePostage  
CLASSID=1MailServicePriority Maillt;supgt;amp;reg;lt;/ 
supgt;/MailServiceRate52.55/ 
RateSpecialServicesSpecialServiceServiceID1/ 
ServiceIDServiceNameInsurance/ServiceNameAvailabletrue/ 
AvailableAvailableOnlinetrue/AvailableOnlinePrice1.95/ 
PricePriceOnline1.95/PriceOnlineDeclaredValueRequiredtrue/ 
DeclaredValueRequiredDueSenderRequiredfalse/DueSenderRequired/ 
SpecialServiceSpecialServiceServiceID0/ 
ServiceIDServiceNameCertified Maillt;supgt;amp;reg;lt;/supgt;/ 
ServiceNameAvailabletrue/AvailableAvailableOnlinefalse/ 
AvailableOnlinePrice3.10/PricePriceOnline0/PriceOnline/ 
SpecialServiceSpecialServiceServiceID19/ 
ServiceIDServiceNameAdult Signature Required/ 
ServiceNameAvailablefalse/AvailableAvailableOnlinetrue/ 
AvailableOnlinePrice0/PricePriceOnline4.95/PriceOnline/ 
SpecialService/SpecialServices/Postage/Package/RateV4Response


This is my attempt to convert. I thought of setting up a blank array  
then filling that array with the specialservice arrays


$data = strstr($result, '?');
// echo '!-- '. $data. ' --'; // Uncomment to show XML in comments
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser,XML_OPTION_TARGET_ENCODING,  
ISO-8859-1);

xml_parse_into_struct($xml_parser, $result, $vals, $index);
xml_parser_free($xml_parser);
$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
	list($level[$xml_elem['level']],$extra) =  
array_values($xml_elem['attributes']);

} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level  $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';

eval($php_stmt);
}
}

... then trying to pull data from the results of the $php_stmt


$sid = array();
$numserv = count($params['RATEV4RESPONSE'][''.$p.$ack.''][$cId] 
['SPECIALSERVICES']);

if($numserv  0) {
	foreach($params['RATEV4RESPONSE'][''.$p.$ack.''][$cId] 
['SPECIALSERVICES']['SPECIALSERVICE'] as $sp_servs) {

$sid_val = 

Re: [PHP] Arrays

2013-02-25 Thread Karl DeSaulniers


On Feb 25, 2013, at 7:50 PM, Jim Lucas wrote:


On 02/25/2013 05:40 PM, Karl DeSaulniers wrote:

Hi Guys/Gals,
If I have an multidimensional array and it has items that have the  
same

name in it, how do I get the values of each similar item?

EG:

specialservices = array(
specialservice = array(
serviceid = 1,
servicename= signature required,
price = $4.95
),
secialservice = array(
serviceid = 15,
servicename = return receipt,
price = $2.30
)
)

How do I get the prices for each? What would be the best way to do  
this?

Can I utilize the serviceid to do this somehow?
It is always going to be different per specialservice.

TIA,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




This will never work.  Your last array will always overwrite your  
previous array.


Here is how I would suggest building it:


$items = array(
   1 = array(
   serviceid = 1,
   servicename= signature required,
   price = $4.95
   ),
   15 = array(
   serviceid = 15,
   servicename = return receipt,
   price = $2.30
   )
)

This will ensure that your first level indexes never overwrite  
themselves.


But, with that change made, then do this:

foreach ( $items AS $item ) {
 if ( array_key_exists('price', $item) ) {
   echo $item['price'];
 } else {
   echo 'Item does not have a price set';
 }
}

Resources:
http://php.net/foreach
http://php.net/array_key_exists

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/



Thanks Jim,
However I have no control over how the USPS sends back the response.
See my more detailed email.

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2013-02-25 Thread Karl DeSaulniers
Never mind. I found a different function that reads out the children  
as well into the array.



function xml_parse_into_assoc($data) {
  $p = xml_parser_create();

  xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
  xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);

  xml_parse_into_struct($p, $data, $vals, $index);
  xml_parser_free($p);

  $levels = array(null);

  foreach ($vals as $val) {
if ($val['type'] == 'open' || $val['type'] == 
'complete') {
  if (!array_key_exists($val['level'], $levels)) {
$levels[$val['level']] = array();
  }
}

$prevLevel = $levels[$val['level'] - 1];
$parent = $prevLevel[sizeof($prevLevel)-1];

if ($val['type'] == 'open') {
  $val['children'] = array();
  array_push($levels[$val['level']], $val);
  continue;
}

else if ($val['type'] == 'complete') {
  $parent['children'][$val['tag']] = $val['value'];
}

else if ($val['type'] == 'close') {
  $pop = array_pop($levels[$val['level']]);
  $tag = $pop['tag'];

  if ($parent) {
if (!array_key_exists($tag, 
$parent['children'])) {
  $parent['children'][$tag] = $pop['children'];
}
else if (is_array($parent['children'][$tag])) {
if(!isset($parent['children'][$tag][0])) {
$oldSingle = $parent['children'][$tag];
$parent['children'][$tag] = null;
$parent['children'][$tag][] = 
$oldSingle;

}
  $parent['children'][$tag][] = 
$pop['children'];
}
  }
  else {
return(array($pop['tag'] = $pop['children']));
  }
}

$prevLevel[sizeof($prevLevel)-1] = $parent;
  }
}


			$params = xml_parse_into_assoc($result);//$result = xml result from  
USPS api


Original function by: jemptymethod at gmail dot com
Duplicate names fix by: Anonymous (comment right above original  
function)


Best,
Karl


On Feb 25, 2013, at 7:50 PM, Jim Lucas wrote:


On 02/25/2013 05:40 PM, Karl DeSaulniers wrote:

Hi Guys/Gals,
If I have an multidimensional array and it has items that have the  
same

name in it, how do I get the values of each similar item?

EG:

specialservices = array(
specialservice = array(
serviceid = 1,
servicename= signature required,
price = $4.95
),
secialservice = array(
serviceid = 15,
servicename = return receipt,
price = $2.30
)
)

How do I get the prices for each? What would be the best way to do  
this?

Can I utilize the serviceid to do this somehow?
It is always going to be different per specialservice.

TIA,

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




This will never work.  Your last array will always overwrite your  
previous array.


Here is how I would suggest building it:


$items = array(
   1 = array(
   serviceid = 1,
   servicename= signature required,
   price = $4.95
   ),
   15 = array(
   serviceid = 15,
   servicename = return receipt,
   price = $2.30
   )
)

This will ensure that your first level indexes never overwrite  
themselves.


But, with that change made, then do this:

foreach ( $items AS $item ) {
 if ( array_key_exists('price', $item) ) {
   echo $item['price'];
 } else {
   echo 'Item does not have a price set';
 }
}

Resources:
http://php.net/foreach
http://php.net/array_key_exists

--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Larry Garfield

On 2/7/12 1:50 PM, Micky Hulse wrote:

Was there ever a time when having a comma at the end of the last array
element was not acceptable in PHP?

I just did a few quick tests:

https://gist.github.com/1761490

... and it looks like having that comma ain't no big deal.

I can't believe that I always thought that having the trailing comma
was a no-no in PHP (maybe I picked that up from my C++ classes in
college? I just don't remember where I picked up this (bad) habit).

I would prefer to have the trailing comma... I just can't believe I
have avoided using it for all these years.

Thanks!
Micky


Drupal's coding standards encourage the extra trailing comma on 
multi-line arrays, for all the readability and editability benefits that 
others have mentioned.  We have for years.  Cool stuff. :-)


--Larry Garfield

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Robert Cummings

On 12-02-07 02:50 PM, Micky Hulse wrote:

Was there ever a time when having a comma at the end of the last array
element was not acceptable in PHP?

I just did a few quick tests:

https://gist.github.com/1761490

... and it looks like having that comma ain't no big deal.

I can't believe that I always thought that having the trailing comma
was a no-no in PHP (maybe I picked that up from my C++ classes in
college? I just don't remember where I picked up this (bad) habit).

I would prefer to have the trailing comma... I just can't believe I
have avoided using it for all these years.


JavaScript in Internet Crapsplorer spanks you on the bottom every time 
you have a trailing comma in a JS array. That may be where you picked up 
the aversion.


Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Micky Hulse
On Wed, Feb 8, 2012 at 9:58 AM, Larry Garfield la...@garfieldtech.com wrote:
 Drupal's coding standards encourage the extra trailing comma on multi-line
 arrays, for all the readability and editability benefits that others have
 mentioned.  We have for years.  Cool stuff. :-)

Yah, I love that syntax guideline/rule in Python (tuples and other
things). I will definitely start doing this in PHP for arrays.

I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D

Thanks again all!

Cheers,
Micky

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Micky Hulse
On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummings rob...@interjinn.com wrote:
 JavaScript in Internet Crapsplorer spanks you on the bottom every time you
 have a trailing comma in a JS array. That may be where you picked up the
 aversion.

On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulse rgmi...@gmail.com wrote:
 I am just surprised that there wasn't an older version of PHP that did
 not allow this... I must have picked up this habit via my JS coding
 knowledge. :D

Jinx! You owe me a Coke!!! :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-08 Thread Robert Cummings

On 12-02-08 01:12 PM, Micky Hulse wrote:

On Wed, Feb 8, 2012 at 10:08 AM, Robert Cummingsrob...@interjinn.com  wrote:

JavaScript in Internet Crapsplorer spanks you on the bottom every time you
have a trailing comma in a JS array. That may be where you picked up the
aversion.


On Wed, Feb 8, 2012 at 10:10 AM, Micky Hulsergmi...@gmail.com  wrote:

I am just surprised that there wasn't an older version of PHP that did
not allow this... I must have picked up this habit via my JS coding
knowledge. :D


Jinx! You owe me a Coke!!! :)


The timestamps above clearly show I was first ;)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ashley Sheridan
On Tue, 2012-02-07 at 11:50 -0800, Micky Hulse wrote:

 Was there ever a time when having a comma at the end of the last array
 element was not acceptable in PHP?
 
 I just did a few quick tests:
 
 https://gist.github.com/1761490
 
 ... and it looks like having that comma ain't no big deal.
 
 I can't believe that I always thought that having the trailing comma
 was a no-no in PHP (maybe I picked that up from my C++ classes in
 college? I just don't remember where I picked up this (bad) habit).
 
 I would prefer to have the trailing comma... I just can't believe I
 have avoided using it for all these years.
 
 Thanks!
 Micky
 


It's fine in PHP, and some coding practices actually encourage it, for
example:

$var = array(
'element',
'element',
'element',
);

It's easy to add and remove elements without making sure you have to
check the trailing comma. It's also OK in Javascript to use the trailing
comma, as long as you don't mind things not working on IE, which is the
only browser that has issues with it. As far as PHP goes though, it's
fine.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Paul M Foster
On Tue, Feb 07, 2012 at 11:50:45AM -0800, Micky Hulse wrote:

 Was there ever a time when having a comma at the end of the last array
 element was not acceptable in PHP?
 
 I just did a few quick tests:
 
 https://gist.github.com/1761490
 
 ... and it looks like having that comma ain't no big deal.
 
 I can't believe that I always thought that having the trailing comma
 was a no-no in PHP (maybe I picked that up from my C++ classes in
 college? I just don't remember where I picked up this (bad) habit).
 
 I would prefer to have the trailing comma... I just can't believe I
 have avoided using it for all these years.
 
 Thanks!
 Micky

I've always avoided trailing array commas, but only because I was under
the impression that leaving one there would append a blank array member
to the array, where it might be problematic. Yes? No?

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
Hi Ashley! Thanks for your quick and informative reply, I really
appreciate it. :)

On Tue, Feb 7, 2012 at 12:10 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 It's easy to add and remove elements without making sure you have to check 
 the trailing comma. It's also OK in Javascript to use the trailing comma, as 
 long as you don't mind things not working on IE, which is the only browser 
 that has issues with it. As far as PHP goes though, it's fine.

Makes sense, thanks!

Gosh, I wonder if I picked up this habit due to my JS coding
knowledge? Anyway, thanks for the clarification. :)

Have an awesome day!

Cheers,
Micky

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ashley Sheridan
On Tue, 2012-02-07 at 15:15 -0500, Paul M Foster wrote:

 On Tue, Feb 07, 2012 at 11:50:45AM -0800, Micky Hulse wrote:
 
  Was there ever a time when having a comma at the end of the last array
  element was not acceptable in PHP?
  
  I just did a few quick tests:
  
  https://gist.github.com/1761490
  
  ... and it looks like having that comma ain't no big deal.
  
  I can't believe that I always thought that having the trailing comma
  was a no-no in PHP (maybe I picked that up from my C++ classes in
  college? I just don't remember where I picked up this (bad) habit).
  
  I would prefer to have the trailing comma... I just can't believe I
  have avoided using it for all these years.
  
  Thanks!
  Micky
 
 I've always avoided trailing array commas, but only because I was under
 the impression that leaving one there would append a blank array member
 to the array, where it might be problematic. Yes? No?
 
 Paul
 
 -- 
 Paul M. Foster
 http://noferblatz.com
 http://quillandmouse.com
 


I've never experienced any blank elements in my arrays, maybe that was a
bug that only existed in very specific scenarios?

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
On Tue, Feb 7, 2012 at 12:15 PM, Paul M Foster pa...@quillandmouse.com wrote:
 I've always avoided trailing array commas, but only because I was under
 the impression that leaving one there would append a blank array member
 to the array, where it might be problematic. Yes? No?

Yah, ditto! :D

In my few simple tests, using PHP5.x, the last comma is ignored.

Just feels strange to have avoided doing something for so long, only
to learn that it's something I need not worry about! :D

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
On Tue, Feb 7, 2012 at 12:19 PM, Micky Hulse rgmi...@gmail.com wrote:
 Yah, ditto! :D

$s = 'foo,bar,';
print_r(explode(',', $s));

The output is:

Array
(
[0] = foo
[1] = bar
[2] =
)

That's one instance where I know you have to be cautious about the
trailing delimiter.

I know, this is all noob stuff... Sorry. :D

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Robert Williams
On 2/7/12 13:15, Paul M Foster pa...@quillandmouse.com wrote:


I've always avoided trailing array commas, but only because I was under
the impression that leaving one there would append a blank array member
to the array, where it might be problematic. Yes? No?

Nope. In fact, it's officially supported syntax:

http://us3.php.net/manual/en/function.array.php

I love it, particularly when used with the already-noted multi-line array
syntax (I don't recommend it with single-line arrangements):

$foo = array(
   1,
   2,
   3,
); //$foo

This makes it dead easy to add, remove, or reorder elements without
worrying about accidentally breaking the syntax. Much like always using
braces around flow-control blocks, this practice makes future bugs less
likely to be born.

Now if only we could have support for trailing commas in SQL UPDATE/INSERT
field and value lists


Regards,
Bob


--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/





Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ashley Sheridan
On Tue, 2012-02-07 at 12:26 -0800, Micky Hulse wrote:

 On Tue, Feb 7, 2012 at 12:19 PM, Micky Hulse rgmi...@gmail.com wrote:
  Yah, ditto! :D
 
 $s = 'foo,bar,';
 print_r(explode(',', $s));
 
 The output is:
 
 Array
 (
 [0] = foo
 [1] = bar
 [2] =
 )
 
 That's one instance where I know you have to be cautious about the
 trailing delimiter.
 
 I know, this is all noob stuff... Sorry. :D
 


That's because it's not an array you've got the trailing delimiter on,
it's a string. We were talking about commas on the end of the last
element in the array, like:

$var = array(
'foo',
'bar',
);

That only contains two elements, and won't have a hidden 3rd at any
time.

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Micky Hulse
On Tue, Feb 7, 2012 at 12:32 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 That's because it's not an array you've got the trailing delimiter on, it's a 
 string.

Right. Sorry, bad example.

it was just the one example I could think of where you could get an
empty element at the end of your array.

Clearly, apples and oranges though.

Thanks!
Micky

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays: Comma at end?

2012-02-07 Thread Ghodmode
On Wed, Feb 8, 2012 at 4:10 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Tue, 2012-02-07 at 11:50 -0800, Micky Hulse wrote:

 Was there ever a time when having a comma at the end of the last array
 element was not acceptable in PHP?
...
 It's fine in PHP, and some coding practices actually encourage it, for
 example:
...

 It's easy to add and remove elements without making sure you have to
 check the trailing comma. It's also OK in Javascript to use the trailing
 comma, as long as you don't mind things not working on IE, which is the
 only browser that has issues with it. As far as PHP goes though, it's
 fine.

I believe this behavior was inherited from Perl.  I used Perl before I
used PHP and it was considered a feature for exactly the reason Ash
gave.

I think that problems with Perl may have originally inspired the
creation of PHP, at least in part.  But they kept the good parts.
This is just my perception.  To confirm it, I'd have to ask our BDFL
:)

--
Vince Aggrippino
a.k.a. Ghodmode
http://www.ghodmode.com


 --
 Thanks,
 Ash
 http://www.ashleysheridan.co.uk



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays passed to functions lose their indexing - how to maintain?

2010-07-09 Thread Ashley Sheridan
On Fri, 2010-07-09 at 15:55 -0400, Marc Guay wrote:

 Hi folks,
 
 I have an array that looks a little something like this:
 
 Array ( [6] = 43.712608, -79.360092 [7] = 43.674088, -79.388557 [8]
 = 43.674088, -79.388557 [9] = 43.704666, -79.397873 [10] =
 43.674393, -79.372147 )
 
 but after I pass it to a function, it loses it's indexing and becomes:
 
 Array ( [0] = 43.712608, -79.360092 [1] = 43.674088, -79.388557 [2]
 = 43.674088, -79.388557 [3] = 43.704666, -79.397873 [4] =
 43.674393, -79.372147 )
 
 The indexing is important and I'd like to hang onto it.  Any ideas?  
 pointers?
 
 Marc
 


Are you passing the array variable by reference? If so, it's probably
the logic of the function that is re-writing the keys. What does the
function look like?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Arrays passed to functions lose their indexing - how to maintain?

2010-07-09 Thread Marc Guay
My bad, I had some leftover code running array_values() on it before
it got passed.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays Regexp - Help Requested

2010-01-01 Thread Mari Masuda
I think the problem is here:

echo 'input type=' . $input_type . ' ';

[...snip...]

elseif ($input_type == 'textarea')
{
 echo 'rows=7 cols=30 ';
 echo 'value=';
 if ($field['null'] == 'YES') // CAN BE NULL?
 {
  echo 'NULL';
 }
 echo ' ';
}

because to create a textarea, the HTML is textarea rows=7 cols=30default 
text/textarea.  It looks like your code is trying to make a textarea that 
starts with input type=' which won't work.  See 
http://www.w3.org/TR/html401/interact/forms.html#h-17.7 for how to use textarea.


On Jan 1, 2010, at 3:38 PM, Allen McCabe wrote:

 echo 'input type=' . $input_type . ' ';
 if ($input_type == 'text')
 {
  echo 'size=';
  $length = printByType($field['type'], 'INPUT_LENGTH');
  echo $length;
  echo ' ';
  echo 'value=';
  if ($field['null'] == 'YES') // CAN BE NULL?
  {
   echo 'NULL';
  }
  echo ' ';
 }
 elseif ($input_type == 'textarea')
 {
  echo 'rows=7 cols=30 ';
  echo 'value=';
  if ($field['null'] == 'YES') // CAN BE NULL?
  {
   echo 'NULL';
  }
  echo ' ';
 }


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays?

2007-01-08 Thread Sumeet
Nicholas Yim wrote:
 Hello William Stokes,
 
 1 write a callback function:
   [php]
   function cmp_forth_value($left,$right){
 return $left[4]$right?-1:($left[4]==$right[4]?0:1);

return $left[4]$right[4]?-1:($left[4]==$right[4]?0:1);
  ^^^
   add this
   }
   [/php]
 
 2 use the usort function
 
   usort($test,'cmp_forth_value');
 
 Best regards, 


-- 
Thanking You

Sumeet Shroff
http://www.prateeksha.com
Web Designers and PHP / Mysql Ecommerce Development, Mumbai India

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays?

2007-01-08 Thread Sumeet
Nicholas Yim wrote:
 Hello William Stokes,
 
 1 write a callback function:
   [php]
   function cmp_forth_value($left,$right){
 return $left[4]$right?-1:($left[4]==$right[4]?0:1);

return $left[4]$right[4]?-1:($left[4]==$right[4]?0:1);
  ^^^
   add this
   }
   [/php]
 
 2 use the usort function
 
   usort($test,'cmp_forth_value');
 
 Best regards, 


-- 
Thanking You

Sumeet Shroff
http://www.prateeksha.com
Web Designers and PHP / Mysql Ecommerce Development, Mumbai India

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays?

2007-01-07 Thread Nicholas Yim
Hello William Stokes,

1 write a callback function:
  [php]
  function cmp_forth_value($left,$right){
return $left[4]$right?-1:($left[4]==$right[4]?0:1);
  }
  [/php]

2 use the usort function

  usort($test,'cmp_forth_value');

Best regards, 
  
=== At 2007-01-08, 14:46:33 you wrote: ===

Hello,

How to print out the following array $test so that the print order is by the 
fourth[4] key? I need to print out all arrays in $test so that the data is 
ordered by the fourth key in ascending order.

$test =Array (
 [0] = Array (
  [0] = 5
  [1] = 2
  [2] = sika
  [3] = sika.php
  [4] = 1 )

 [1] = Array (
  [0] = 8
  [1] =2
  [2] = Hono
  [3] = hono.php
  [4] = 1 )

 [2] = Array (
  [0] = 7
  [1] = 2
  [2] = Kameli
  [3] = kameli.php
  [4] = 4 )

 [3] = Array (
  [0] = 6
  [1] = 2
  [2] = koira
  [3] = koira.php
  [4] = 2 )
  )

The way that the data is strored to $test makes it difficult/impossible to 
sort stuff the way I need here while reading it from DB.

Thanks
-Will 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



= = = = = = = = = = = = = = = = = = = =

Nicholas Yim
[EMAIL PROTECTED]
2007-01-08

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays help

2007-01-05 Thread Robert Cummings
On Fri, 2007-01-05 at 18:48 +0200, William Stokes wrote:
 Hello,
 
 I'm making a menu script that uses mysql, php and javascript to build a on 
 mouse over dropdown menu to a page. I ran into some problems and would need 
 help to get this working. (This is just the top level of the menusystem)
 
 1. Get the toplevel links from DB, create array and put values there.
 
 $sql =SELECT * FROM x_menu WHERE menulevel = '1' ORDER BY 'id' ASC;

Yeesh... should be using parent ID references. How does a sub-menu item
know to which menu item it belongs? It has a parent right? What
determines a root menu entry? No parent (or root node parent)... What
is this wierd menulevel field?

 $result=mysql_query($sql);
 $num = mysql_num_rows($result);
 $cur = 1;
 while ($num = $cur) {
 $row = mysql_fetch_array($result);
 $id = $row[id];
 $menulevel = $row[menulevel];
 $linktext = $row[linktext];
 $linkurl = $row[linkurl];
 $toplevel =array($id, $menulevel, $linktext, $linkurl);
 $cur ++;
 }
 
 The first problem comes here. How can I create a different array at every 
 iteration of the loop? Or how this should be done if the toplevel objects 
 are echoed with foreach to the browser like this:

Just create the array at each iteration of the loop...

$foo = array( /* put some data in it */ )

 
 $TopLevelCounter = 1;
 foreach ($toplevel as $value){
 print menuSyS.addItem('labelItem', '$toplevel[2]', $TopLevelCounter, 
 $width, '$colour1', '#aa', '$colour2');\n;
 $TopLevelCounter ++;
 }
 
 Now, because I just fill the same array again and again in the DB query all 
 top level items finally contain the same text. So my question is how to 
 query the DB and create the arrays so that it would be easy to refer to the 
 data in the arrays when printing to screen. Do I have to make 
 multidimensional arrays?

Yes.

  If so how to implement them here and how they 
 should be referred to when printing to browser?

Use a foreach loop for the menu array. When you come across a menu item
with children, use another foreach loop. Alternatively you can use
recursion.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays

2006-07-10 Thread tedd
At 3:38 PM -0400 7/10/06, Dallas Cahker wrote:
Banging my head against a wall with arrays, maybe someone can help me with
the answer.

I have a db query that returns results from 1-100 or more.
I want to put the results into an array and pull them out elsewhere.
I want them to be pulled out in an orderly and expected fashion.

Dallas:

Place the sorting on MySQL -- it has great ways of providing data for you.

Perhaps this link might help:

http://www.weberdev.com/get_example-4270.html

tedd
-- 

http://sperling.com  http://ancientstones.com  http://earthstones.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays

2006-07-10 Thread Stut

Dallas Cahker wrote:

Banging my head against a wall with arrays, maybe someone can help me with
the answer.

I have a db query that returns results from 1-100 or more.
I want to put the results into an array and pull them out elsewhere.
I want them to be pulled out in an orderly and expected fashion.

part of function

$sql=Select * FROM blah Where blahid='1';
run sql
while ($row=mysql_fetch_array($result)) {
$oarray=array('blah1' = $row['lah1'], 'blah2' = $row['lah2'], 'blah3' =
$row['lah3']);


The above line will not add an array element per row. Change $oarray= to 
$oarray[]=



}
return $oarray


part of display

$OLength=count($oarray);

for ($i = 0; $i  $OLength; $i++){
 echo O1 : .$oarray['blah1'][$i].br;
 echo O2 : .$oarray['blah2'][$i].br;
 echo O3 : .$oarray['blah3'][$i].br;
}


This is not the way the array is arranged. Switch your indices around so 
it's like so...


echo O1 : .$oarray[$i]['blah1'].br;
echo O2 : .$oarray[$i]['blah2'].br;
echo O3 : .$oarray[$i]['blah3'].br;


this gets me nothing, and I am unsure where I am going wrong, other then 
all

over the place.


-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays

2006-07-10 Thread Brad Bonkoski

When loading the array you will only ever get the last record returned...
so count($oarray) will always be 1?

Perhaps something like this:
Function
$sql = ...;
$ret = array();
while($row = mysql_feth_array($reault)) {
array_push($ret, $row);
}
return $ret;

then...
$data = function();
$c = count($data);
for($i=0; $i$c; $i++) {
$row = $data[$i];
print_r($row);
}

Should give you what you want...
As for your orderly fashion, I would put this load on the database, 
and not really PHP...
if you want to make it associate you can...just push the assocative onto 
another array so you get the complete set...

-B

Dallas Cahker wrote:

Banging my head against a wall with arrays, maybe someone can help me 
with

the answer.

I have a db query that returns results from 1-100 or more.
I want to put the results into an array and pull them out elsewhere.
I want them to be pulled out in an orderly and expected fashion.

part of function

$sql=Select * FROM blah Where blahid='1';
run sql
while ($row=mysql_fetch_array($result)) {
$oarray=array('blah1' = $row['lah1'], 'blah2' = $row['lah2'], 
'blah3' =

$row['lah3']);
}
return $oarray


part of display

$OLength=count($oarray);

for ($i = 0; $i  $OLength; $i++){
 echo O1 : .$oarray['blah1'][$i].br;
 echo O2 : .$oarray['blah2'][$i].br;
 echo O3 : .$oarray['blah3'][$i].br;
}

this gets me nothing, and I am unsure where I am going wrong, other 
then all

over the place.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays

2006-07-10 Thread Dallas Cahker

Both work great.
Thanks

On 7/10/06, Brad Bonkoski [EMAIL PROTECTED] wrote:


When loading the array you will only ever get the last record returned...
so count($oarray) will always be 1?

Perhaps something like this:
Function
$sql = ...;
$ret = array();
while($row = mysql_feth_array($reault)) {
array_push($ret, $row);
}
return $ret;

then...
$data = function();
$c = count($data);
for($i=0; $i$c; $i++) {
$row = $data[$i];
print_r($row);
}

Should give you what you want...
As for your orderly fashion, I would put this load on the database,
and not really PHP...
if you want to make it associate you can...just push the assocative onto
another array so you get the complete set...
-B

Dallas Cahker wrote:

 Banging my head against a wall with arrays, maybe someone can help me
 with
 the answer.

 I have a db query that returns results from 1-100 or more.
 I want to put the results into an array and pull them out elsewhere.
 I want them to be pulled out in an orderly and expected fashion.

 part of function

 $sql=Select * FROM blah Where blahid='1';
 run sql
 while ($row=mysql_fetch_array($result)) {
 $oarray=array('blah1' = $row['lah1'], 'blah2' = $row['lah2'],
 'blah3' =
 $row['lah3']);
 }
 return $oarray


 part of display

 $OLength=count($oarray);

 for ($i = 0; $i  $OLength; $i++){
  echo O1 : .$oarray['blah1'][$i].br;
  echo O2 : .$oarray['blah2'][$i].br;
  echo O3 : .$oarray['blah3'][$i].br;
 }

 this gets me nothing, and I am unsure where I am going wrong, other
 then all
 over the place.





RE: [PHP] arrays

2006-06-09 Thread Jay Blanchard
[snip]
if I have two arrays, example:

$a = array (one, two, three, four, two);

$b = array (seven, one, three, six, five);

How can I get in another variable a new array with the same elements into $a 
and $b.
[/snip]

http://www.php.net/array_merge

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays

2006-06-09 Thread Dave Goodchild

Hola Jesus. Hablo un pocitio espanol, pero en ingles no estoy seguro que
quieres decir. Si te ayudara, envia el mensaje otra vez en espanol y tratare
comprender.

On 09/06/06, Jesús Alain Rodríguez Santos [EMAIL PROTECTED] wrote:


if I have two arrays, example:

$a = array (one, two, three, four, two);

$b = array (seven, one, three, six, five);

How can I get in another variable a new array with the same elements into
$a and $b.
--
Este mensaje ha sido analizado por MailScanner
en busca de virus y otros contenidos peligrosos,
y se considera que está limpio.






--
http://www.web-buddha.co.uk

dynamic web programming from Reigate, Surrey UK (php, mysql, xhtml, css)

look out for project karma, our new venture, coming soon!


Re: [PHP] arrays

2006-06-09 Thread Rabin Vincent

On 6/9/06, Jesús Alain Rodríguez Santos [EMAIL PROTECTED] wrote:

if I have two arrays, example:

$a = array (one, two, three, four, two);

$b = array (seven, one, three, six, five);

How can I get in another variable a new array with the same elements into $a 
and $b.


php.net/array_intersect will get you the common elements.

Rabin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays

2006-06-09 Thread Mariano Guadagnini




Jess Alain Rodrguez Santos wrote:

  if I have two arrays, example:

$a = array ("one", "two", "three", "four", "two");

$b = array ("seven", "one", "three", "six", "five");

How can I get in another variable a new array with the same elements into $a and $b.
  
  


  

$new_array = array_merge( $a, $b);

regards,

Mariano Guadagnini.


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.8.3/359 - Release Date: 08/06/2006

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Arrays

2006-02-04 Thread Paul Novitski

At 11:12 AM 2/4/2006, Philip W. wrote:

When using the following string format, I get an error from PHP.

$text['text'] = String Text ;


Hi Philip,

If that's literally a line from your script, my guess is that text 
is a reserved word and can't be used as a variable name.  Try $sText 
or $sSomethingMeaningful.


In this and future postings, it would help us help you if you share 
all relevant details such as the exact error message you see.



I've gotten into the habit of prefixing all my variable names with their type:

$aSomething - array
$sSomething - string
$iSomething - integer
$nSomething - numeric
$bSomething - Boolean

In a language like PHP in which data typing is so loose, I find that 
prefixing the variable type a) helps me keep variables straight and 
b) prevents me from inadvertantly using reserved words as variable names.


Great resource:
http://php.net/

You can quickly look up details from the reference guide by entering 
key words after the domain name, for example:

http://php.net/array
gets you a page of array functions.

Have fun,
Paul 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2006-02-04 Thread Hugh Danaher

Philip,
You'll often get an error call on a line when there is a problem on the 
previous line.  Say, you forgot to end a line with a semicolon, then it will 
error the next line.

Hugh
- Original Message - 
From: Philip W. [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Saturday, February 04, 2006 11:12 AM
Subject: [PHP] Arrays


Sorry if this question seems stupid - I've only had 3 days of PHP 
experience.


When using the following string format, I get an error from PHP.

$text['text'] = String Text ;

Can someone help me?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.1/250 - Release Date: 2/3/2006






--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 267.15.1/250 - Release Date: 2/3/2006

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Arrays

2005-12-06 Thread Jay Blanchard
[snip]
Is there a way to quickly check to see if $Var contains Lion without
walking through each value?
[/snip]

http://us3.php.net/in_array

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2005-12-06 Thread Richard Davey

On 6 Dec 2005, at 17:33, Ben Miller wrote:


If I have an array, such as

$Var[0] = Dog;
$Var[1] = Cat;
$Var[2] = Horse;

Is there a way to quickly check to see if $Var contains Lion without
walking through each value?


Look in the manual at the function in_array()

Cheers,

Rich
--
http://www.corephp.co.uk
PHP Development Services

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2005-12-06 Thread tg-php
This what you want?

http://us3.php.net/manual/en/function.array-search.php

-TG

= = = Original message = = =

If I have an array, such as

$Var[0] = Dog;
$Var[1] = Cat;
$Var[2] = Horse;

Is there a way to quickly check to see if $Var contains Lion without
walking through each value?


___
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays question

2005-11-12 Thread Brian V Bonini
On Fri, 2005-11-11 at 15:25, cybermalandro cybermalandro wrote:
 I have this that looks like this
 
 array(3) {
   [0]=
   array(2) {
 [0]=
 string(1) 1
 [1]=
 string(1) 2
   }
   [1]=
   array(2) {
 [0]=
 string(3) 492
 [1]=
 string(3) 211
   }
   [2]=
   array(2) {
 [0]=
 string(2) 11
 [1]=
 string(2) 20
   }
 }
 
 I want to loop through so I can get and print 1,492,11 and
 2,211,20 What is the best way to do this? I suck with arrays and
 I can't get my looping right.

$a = array(array(1,2),
   array(492,211),
   array(11,20)
 );

for($i=0;$i2;$i++) {
foreach($a as $v) {
echo $v[$i] . \n;
}

echo ==\n;
}

Prints:

1
492
11
==
2
211
20
==


-Brian
-- 

s/:-[(/]/:-)/g


BrianGnuPG - KeyID: 0x04A4F0DC | Key Server: pgp.mit.edu
==
gpg --keyserver pgp.mit.edu --recv-keys 04A4F0DC
Key Info: http://gfx-design.com/keys
Linux Registered User #339825 at http://counter.li.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays question

2005-11-11 Thread Brent Baisley
Here's a few loops that should work. You can actually just use the  
first loop to concatenate text string instead create array items, but  
I wasn't sure what type of processing you wanted to do with the result.


//Convert Array from 3 rows by 2 cols - 2 rows by 3 cols
for($i=0; $icount($mainArray); $i++ ) {
for ( $x=0; $xcount($mainArray[$i]); $x++ ) {
$resultArray[$x][]= $mainArray[$i][$x];
}
}

Resulting Array
Array
(
[0] = Array
(
[0] = 1
[1] = 492
[2] = 11
)

[1] = Array
(
[0] = 2
[1] = 211
[2] = 20
)
)

//Convert array items to text string with , separator
for($i=0; $icount($resultArray); $i++) {
$resultArray[$i]= ''.implode(',',$resultArray[$i]).'';
}

Resulting Array:
Array
(
[0] = 1,492,11
[1] = 2,211,20
)


On Nov 11, 2005, at 3:25 PM, cybermalandro cybermalandro wrote:


I have this that looks like this

array(3) {
  [0]=
  array(2) {
[0]=
string(1) 1
[1]=
string(1) 2
  }
  [1]=
  array(2) {
[0]=
string(3) 492
[1]=
string(3) 211
  }
  [2]=
  array(2) {
[0]=
string(2) 11
[1]=
string(2) 20
  }
}

I want to loop through so I can get and print 1,492,11 and
2,211,20 What is the best way to do this? I suck with arrays and
I can't get my looping right.

Thanks for your help anybody!



--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2005-07-12 Thread olivier
Hello,

You may try unset($product) in your loop if you want to delete this var.
Your code $product=array(); must work too...
Another way, must be to use something like this $product[id]=$product_id;

But i dont think it's your real goal?!
Could you give some more information about that?

Olivier

Ps: documentation for unset :
http://www.php.net/manual/en/function.unset.php

Le Mardi 12 Juillet 2005 13:34, [EMAIL PROTECTED] a écrit :
 Hi,

 How can i destroy an array?
 I mean i have a loop and for each new value in the loop i want to destroy
 the array. Something like that:

  while($row = mysql_fetch_array($result))
   {

   $product[] = $product_id;

  // some code here

  }

 I've tried this but doesn't work

  while($row = mysql_fetch_array($result))
   {

   $product = array();

   $product[] = $product_id;

  // some code here

  }

 Any help would be appreciated !!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2005-07-12 Thread Justin Gruenberg
On 12/07/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,
 
 How can i destroy an array?
 I mean i have a loop and for each new value in the loop i want to destroy the 
 array. Something like that:
 
  while($row = mysql_fetch_array($result))
   {
 
   $product[] = $product_id;
 
  // some code here
 
  }
 
 I've tried this but doesn't work
 
  while($row = mysql_fetch_array($result))
   {
 
   $product = array();
 
   $product[] = $product_id;
 
  // some code here
 
  }


To destroy an array? 

First of all, where does $product_id come from?  You gave us no code
that gives us that.

Second, if you're trying to make an array populated with a feild from
each row returned, your first example will work, but not the second. 
The second example will empty the array, and start a new one (which
doesn't make sense to me why you would do that--because in the end,
you're only going to have the array with the last row returned).

But if you're trying to destroy an array doing either:
unset($an_array)
or $an_array = array();
will do the job.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Arrays

2005-07-12 Thread yanghshiqi
I guess your purpose is to just save the row data from the mysql to the
array each unit. So may be the result that you expected is sth like:
$product[0] = 1;
$product[1] = 2;
$product[2] = 3;
..

If you just loop for each new value in the loop and to destroy the array,
you second example is okey.
 
 
 
Best regards,
Shiqi Yang
-Original Message-
From: Justin Gruenberg [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 12, 2005 7:43 PM
To: [EMAIL PROTECTED]; php-general@lists.php.net
Subject: Re: [PHP] Arrays

On 12/07/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Hi,
 
 How can i destroy an array?
 I mean i have a loop and for each new value in the loop i want to destroy
the array. Something like that:
 
  while($row = mysql_fetch_array($result))
   {
 
   $product[] = $product_id;
 
  // some code here
 
  }
 
 I've tried this but doesn't work
 
  while($row = mysql_fetch_array($result))
   {
 
   $product = array();
 
   $product[] = $product_id;
 
  // some code here
 
  }


To destroy an array? 

First of all, where does $product_id come from?  You gave us no code
that gives us that.

Second, if you're trying to make an array populated with a feild from
each row returned, your first example will work, but not the second. 
The second example will empty the array, and start a new one (which
doesn't make sense to me why you would do that--because in the end,
you're only going to have the array with the last row returned).

But if you're trying to destroy an array doing either:
unset($an_array)
or $an_array = array();
will do the job.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2004-12-29 Thread Brent Baisley
You can absolutely use arrays as form field names. They allow great 
flexibility. Although you wouldn't use quotes for the array keys.
So your form field name would be something like:
att[keyname]

While in PHP, the same array would look like:
$att['keyname']
Your array id's are consider keys since they are not sequential. Just 
treat them as names for the array entry. There are a number of ways to 
reference it.
$att = $_POST['att'];
foreach($att as $attkey=$attval) {
	echo $att[$attkey];
	echo $attval;
}

Or you could use the array_keys functions to get the keys to the array 
in it's own array that can be referenced sequentially.
$att = $_POST['att'];
$attkeys = array_keys($att);
echo $att[$attkeys[0]];
echo $att[$attkeys[1]];
etc.

You can even use multidimensional arrays as form field names, which is 
helpful when you need to keep separate form fields related. Like having 
multiple phone number/phone description fields:
input type=text name=phone[home][desc] value=Vacation Home 
size=10
input type=text name=phone[home][number] value=123456789 
size=10

input type=text name=phone[work][desc] value=Uptown Office 
size=10
input type=text name=phone[work][number] value=123456789 
size=10

On Dec 28, 2004, at 10:52 PM, GH wrote:
Would it be possible in a form fields name to make it an array?
This way it would be i.e. att[$part_id]
Now is there a way to iterate through the array when I submit the form
to process it, being that the ID numbers are not going to be
sequential and that there will be some numbers not included?
I.E. the id's would be 1, 5, 6, 7, 20, 43
and how would I refence it? would it be $_POST['att']['[partIDhere}'] ?
Thanks
G
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search  Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Arrays

2004-11-11 Thread James E Hicks III
Ben Miller wrote:
edit
I hope this is not a stupid question, but I am learning how to work with
Arrays, and am having trouble figuring out how to move array values [the
whole array and all of it's values] from
page to page and/or store in a db.  

?
echo (htmlheadtitleArray Example/title/headbody);
echo (form action=\.$_SERVER['PHP_SELF'].\ method=\POST\);
for ($i=0; $icount($array_variable); $i++){
   echo (input name=\array_variable[]\ type=\hidden\ 
value=\.$array_variable[$i].\);
}

##-- Add to the array?
echo (input name=\array_variable[]\ type=\text\ value=\\);
echo (input name=\submit\ type=\submit\ value=\Add to the Array\);
echo (/form);
echo (br);
echo (Current Array Elements:);
for ($i=0; $icount($array_variable); $i++){
   echo (BR.$array_variable[$i]);
}
echo (/body/html);
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Arrays

2004-11-09 Thread Klaus Reimer
Zareef Ahmed wrote:
But you need to do serialize and unserialize in case of array or object.
Do ::
$val_ar=array(one,two,three);
$_SESSION['val_ar_store']=serialize($val_ar);
Serialization is done automatically. You don't need to do it yourself. 
You can even store simple value-objects in the session witout manual 
serialization.

So you can do:
$val_ar = array(one, two, three);
$_SESSION['val_ar_store'] = $val_ar;
serialize/unserialize are useful if you want to store complex data in a 
file or in a database.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Arrays

2004-11-08 Thread Ben Miller
edit


I hope this is not a stupid question, but I am learning how to work with
Arrays, and am having trouble figuring out how to move array values [the
whole array and all of it's values] from
page to page and/or store in a db.  Once again, I am new to arrays (and
fairly new to PHP for that matter), so please don't get too technical in
replies.  Thanks so much for help.

ben

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2004-11-08 Thread Greg Donald
On Mon, 8 Nov 2004 16:01:16 -0700, Ben [EMAIL PROTECTED] wrote:
 I hope this is not a stupid question, but I am learning how to work with
 Arrays, and am having trouble figuring out how to move array values from
 page to page and/or store in a db.  Once again, I am new to arrays (and
 fairly new to PHP for that matter), so please don't get too technical in
 replies.  Thanks so much for help.

Where is you (broken) PHP code that you have written so far?

What is it not doing that you are expecting it to do?


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Arrays

2004-11-08 Thread Zareef Ahmed

Hi Ben,

 Welcome to the wonderful world of PHP.

Working with array in PHP is very easy. A large number of functions are
there.
Please visit the manual
http://www.phpcertification.com/manual.php/ref.array.html

You can move values ( including Arrays) from page to page in session
variables.

But you need to do serialize and unserialize in case of array or object.


Do ::

$val_ar=array(one,two,three);
$_SESSION['val_ar_store']=serialize($val_ar);

Now you can get your array in any page simply

$val_ar=unserialize($_SESSION['val_ar_store']);
Print_r($val_ar);

This process is very simple. Please see manual

http://www.phpcertification.com/manual.php/function.serialize.html

http://www.phpcertification.com/manual.php/function.unserialize.html

Revert back with any other problem.

Zareef ahmed 



-Original Message-
From: Ben [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 09, 2004 4:31 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Arrays


I hope this is not a stupid question, but I am learning how to work with

Arrays, and am having trouble figuring out how to move array values from

page to page and/or store in a db.  Once again, I am new to arrays (and 
fairly new to PHP for that matter), so please don't get too technical in

replies.  Thanks so much for help.

ben 


--
Zareef Ahmed :: A PHP develoepr in Delhi ( India )
Homepage :: http://www.zasaifi.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2004-11-08 Thread Ligaya Turmelle
There are a couple of ways to pass arrays (and their values) between 
pages.  I personally would put the array into a session variable 
($_SESSION - see reference) and access the various parts as needed. 
Another option is sending the whole array or it's parts as hidden fields 
in a form (access with the $_GET and $_POST - again see reference), but 
that means the user has to click a submit button.

If you are trying to store the array in a Database I would suggest you 
make each element of the array into it's own column of the database. 
Databases generally should only have 1 piece of information being saved 
per cell (think excel).  If you would like a link to database design, 
let me know and I will send it.

If all you really were asking was how to iterate through an array - then 
 I would recommend looking at the manual's page on arrays ( 
http://www.php.net/manual/en/language.types.array.php ).

Respectfully,
Ligaya Turmelle
References:
http://www.php.net/language.variables.predefined
Ben wrote:
I hope this is not a stupid question, but I am learning how to work with 
Arrays, and am having trouble figuring out how to move array values from 
page to page and/or store in a db.  Once again, I am new to arrays (and 
fairly new to PHP for that matter), so please don't get too technical in 
replies.  Thanks so much for help.

ben 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: [PHP] Arrays

2004-11-08 Thread Ben Miller
Thank you to all for help with this.  Once I have a general idea of which
path to head down, I can figure it out pretty well from there, and you have
all given me a pretty good road map.  Anyway, thanks again.  It is greatly
appreciated.  I'll let you know hot it all comes out.

Ben

-Original Message-
From: Ligaya Turmelle [mailto:[EMAIL PROTECTED]
Sent: Monday, November 08, 2004 10:03 PM
To: Ben
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Arrays


There are a couple of ways to pass arrays (and their values) between
pages.  I personally would put the array into a session variable
($_SESSION - see reference) and access the various parts as needed.
Another option is sending the whole array or it's parts as hidden fields
in a form (access with the $_GET and $_POST - again see reference), but
that means the user has to click a submit button.

If you are trying to store the array in a Database I would suggest you
make each element of the array into it's own column of the database.
Databases generally should only have 1 piece of information being saved
per cell (think excel).  If you would like a link to database design,
let me know and I will send it.

If all you really were asking was how to iterate through an array - then
  I would recommend looking at the manual's page on arrays (
http://www.php.net/manual/en/language.types.array.php ).

Respectfully,
Ligaya Turmelle

References:
http://www.php.net/language.variables.predefined

Ben wrote:
 I hope this is not a stupid question, but I am learning how to work with
 Arrays, and am having trouble figuring out how to move array values from
 page to page and/or store in a db.  Once again, I am new to arrays (and
 fairly new to PHP for that matter), so please don't get too technical in
 replies.  Thanks so much for help.

 ben


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread John Holmes
 From: Vern [EMAIL PROTECTED]

 How can I now get this output displyed in groups 
 of 10 so that I can display them 10 at a time on 
 a page then click a next button to dispaly they 
 next 10 and so forth?

Can't you do all that sorting in your query so you can just retrieve 10 rows at a time 
using LIMIT?

---John Holmes...

UCCASS - PHP Survey System
http://www.bigredspark.com/survey.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Vern
Problem with that is it sorts according the results of the recordset range.

For instance:

It will show the user 1 trhough 10 sorted by miles then 20 - 30 sorted by
miles, however, in 1 through 10 could have a range of 0 to 1000 miles and
the next set will have 5 to 200 miles. What I need is to sort them all by
miles first. The only way I know to do that is to do the way I set it up. So
if I create an array, sort that array by the miles then use that array.
However the array is different that the recordset and thus does not use
LIMIT.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Torsten Roehr
Vern [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Problem with that is it sorts according the results of the recordset
range.

 For instance:

 It will show the user 1 trhough 10 sorted by miles then 20 - 30 sorted by
 miles, however, in 1 through 10 could have a range of 0 to 1000 miles and
 the next set will have 5 to 200 miles. What I need is to sort them all by
 miles first. The only way I know to do that is to do the way I set it up.
So
 if I create an array, sort that array by the miles then use that array.
 However the array is different that the recordset and thus does not use
 LIMIT.

What about this:
SELECT * FROM table ORDER BY miles LIMIT 0, 10

Then pass the offset to your query function and exchange it with 0:
SELECT * FROM table ORDER BY miles LIMIT $offset, 10

Of course you have to properly validate that $offset is an integer before
using it in the query.

Regards, Torsten Roehr

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Vern
The miles are being caluculated during the loop that is created using the
recordset not in the database.

First I create a do..while loop to get the miles

do {
 $k = 0;

 //SET FIRST ARRAY OF ONLINE USERS AND CALCULATE MILES
  do {
//GEOZIP
   $zip2 = $row_rsUSERIDID['zip'];
   $coor1=mycoors($zip1);
   $coor2=mycoors($zip2);
   $line1=split(\|,$coor1);
   $line2=split(\|,$coor2);
   $totaldist=distance($line1[0],$line1[1],$line2[0],$line2[1],mi);

 //SET NEW ARRAY WITH MILES
   $z['username'][$k] = $row_rsUSERIDID['uname'];
   $z['distance'][$k++] = $totaldist;
  } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));


  //SET NEW ARRAY
  $z['user'] = $z['username'];

  //SORT BY DISTANCES
  natsort ($z['distance']);
  reset ($z['distance']);

//DISPLAY USER INFORMATION SORTED BY MILES
  foreach($z['distance'] as $k = $v){
  $newuser = $z['user'][$k];
  echo $newuser .  -  . $v . br;
 }

} while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));

I now what to display this info 10 records at a time.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Curt Zirzow
* Thus wrote Vern:
 I'm setting up an array based on recordset that does a loop as follows:
 
 do {
 //SET ARRAYS
 $z['username'][$k] = $row_rsUSERIDID['uname'];
 $z['distance'][$k++] = $totaldist;
 } while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));
 
...
 
 How can I now get this output displyed in groups of 10 so that I can display
 them 10 at a time on a page then click a next button to dispaly they next 10
 and so forth?

Well, this is the hard way to do things, and very inefficient but:

 foreach(array_slice($z['distance'], $start, 10) {
   //...
 }


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Vern

 Well, this is the hard way to do things, and very inefficient but:

  foreach(array_slice($z['distance'], $start, 10) {
//...
  }

If you think there's a better way of doing it I would like to hear it.

However this is resulting in an Parse error on the foreach line:

  foreach(array_slice($z['distance'], $start, 10)) {
  $newuser = $z['user'][$k];
  echo $newuser .  -  . $v . br;
   }

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Michal Migurski
 If you think there's a better way of doing it I would like to hear it.

 However this is resulting in an Parse error on the foreach line:

   foreach(array_slice($z['distance'], $start, 10)) {
   $newuser = $z['user'][$k];
   echo $newuser .  -  . $v . br;
}

foreach needs an as, probably that was meant to say:
foreach(array_slice($z['distance'], $start, 10) as $k = $v) { ...

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Chris W. Parker
Jason Davidson mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 12:25 AM said:

 would the following example be faster or slower had i simply done
 $this-myArray[$i] = $i;

 class MyClass {
 var $myArray = array();
 
 function MyClass() {
 $myTempArray = array();
 for($i=0;$i100;$i++)
 $myTempArray[$i] = $i;
 $this-myArray = $myTempArray;
}
 }

here's how i would do it (coding styles aside):

function MyClass()
{
$limit = 100;

$i = -1;
while(++$i  $limit)
{
$this-myArray[] = $i;
}
}



chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays, loops, vars and props

2004-03-10 Thread Luis Mirabal
i would do it this way

function MyClass()
{
$this-myArray = range(0, 99);
}

luis.


Chris W. Parker [EMAIL PROTECTED] escribió en el mensaje
news:[EMAIL PROTECTED]
Jason Davidson mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 12:25 AM said:

 would the following example be faster or slower had i simply done
 $this-myArray[$i] = $i;

 class MyClass {
 var $myArray = array();

 function MyClass() {
 $myTempArray = array();
 for($i=0;$i100;$i++)
 $myTempArray[$i] = $i;
 $this-myArray = $myTempArray;
}
 }

here's how i would do it (coding styles aside):

function MyClass()
{
$limit = 100;

$i = -1;
while(++$i  $limit)
{
$this-myArray[] = $i;
}
}



chris.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Michal Migurski
here's how i would do it (coding styles aside):

function MyClass()
{
$limit = 100;

$i = -1;
while(++$i  $limit)
{
$this-myArray[] = $i;
}
}

Don't forget poor old range:

$this-myArray = range(0, 99);

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Chris W. Parker
Luis Mirabal mailto:[EMAIL PROTECTED]
on Wednesday, March 10, 2004 12:30 PM said:

 i would do it this way
 
 function MyClass()
 {
 $this-myArray = range(0, 99);
 }

guys (luis), guys (mike), let's not try to one-up each other...

...

...

but i would take it a step further. :P

function MyClass($limit = 100)
{
$this-myArray = range(0, $limit-1);
}



c.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Jason Davidson
Im fully aware of diffrent ways of doing it, my question is, in the 2
ways i mentioned, which is more efficient.  Ill take the question to
the internals list. Thanks for your responses.

Jason





Chris W. Parker [EMAIL PROTECTED] wrote:
 
 Luis Mirabal mailto:[EMAIL PROTECTED]
 on Wednesday, March 10, 2004 12:30 PM said:
 
  i would do it this way
  
  function MyClass()
  {
  $this-myArray = range(0, 99);
  }
 
 guys (luis), guys (mike), let's not try to one-up each other...
 
 ...
 
 ...
 
 but i would take it a step further. :P
 
 function MyClass($limit = 100)
 {
   $this-myArray = range(0, $limit-1);
 }
 
 
 
 c.
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and sessions

2004-02-27 Thread Chris W. Parker
Kermit Short mailto:[EMAIL PROTECTED]
on Friday, February 27, 2004 1:47 PM said:

 A second form will contain an action that
 sends the sql code for creating the table to the database server, and
 viola, I've got myself a new table.

i prefer the violin, but viola's are cool too. ;)

 If anyone has any
 suggestions on how I can get this done I'd appreciate it!

wait.. i don't understand. you're asking us for a method to accomplish
what you describe or are you looking for help with a problem you're
having?? if the former, your method *sounds* ok to me. if the latter
please post the error you're getting.

 I'd really
 rather not post my whole code file, as it's really big and long, and
 emphasizes how novice I am at PHP.

good choice.


 Thanks in advance for your help!

no problem.


 -Kermit

is your real name Kermit?




chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and sessions

2004-02-27 Thread Kermit Short
I've got some code and it simply isn't working.  I thought it might be
because each time the form submits data, the array I'm storing information
in is being re-initialized.  If this is the case, I don't have the
multidimensional array I'm trying to get, but just a vector array with the
most recent submission data.  I tried making the array a session variable,
but I'm not even sure the session part of it is working.  So, if you have
any methods that you think might work better than what I'm trying to do, I'd
love to hear about it.  Basically, my file is structured like this:

1. Pull in POST data, and store them in php variables
2. If the POST data is null, display the first form and get the table name,
field name, field type, primary key, and null allowed information.  On
submit, the information is stored in an array.
3. If the POST data is not null, again display the entry form in case the
user needs to add more fields, and step through the array to display the
existing table info that the user has already entered.  A button in a second
form is also displayed.  When clicked, it actually creates the table.

My problems are that when I try to step through the array and display its
current contents, I get index not defined errors on my for loop indices
(?!).  The second problem is, when I try to use the print_r function to
display my array, it only displays one set of data.  This might be because
I'm trying to do a C++ type 2 dimensional array concept when PHP arrays are
associative by nature, and I'm not sure how to get around this.
Suggestions?

(Yes, Kermit is my real name.  Miss Piggy is well, and sends her regards.)

-Kermit

Chris W. Parker [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Kermit Short mailto:[EMAIL PROTECTED]
on Friday, February 27, 2004 1:47 PM said:

 A second form will contain an action that
 sends the sql code for creating the table to the database server, and
 viola, I've got myself a new table.

i prefer the violin, but viola's are cool too. ;)

 If anyone has any
 suggestions on how I can get this done I'd appreciate it!

wait.. i don't understand. you're asking us for a method to accomplish
what you describe or are you looking for help with a problem you're
having?? if the former, your method *sounds* ok to me. if the latter
please post the error you're getting.

 I'd really
 rather not post my whole code file, as it's really big and long, and
 emphasizes how novice I am at PHP.

good choice.


 Thanks in advance for your help!

no problem.


 -Kermit

is your real name Kermit?




chris.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and sessions

2004-02-27 Thread Chris W. Parker
Kermit Short mailto:[EMAIL PROTECTED]
on Friday, February 27, 2004 2:10 PM said:

 I've got some code and it simply isn't working.  I thought it might be
 because each time the form submits data, the array I'm storing
 information in is being re-initialized.  If this is the case, I don't
 have the multidimensional array I'm trying to get, but just a vector
 array with the most recent submission data.

here are some thoughts...

sounds like you're just not keeping track of each iteration. i mean,
within the session variable you need to somehow differentiate between
each subsequent form submittal.

?php

  $iteration = ++$_POST['iteration'];

  $_SESSION['post_data'][$iteration] = $_POST;

  // include $iteration in the post data
  // so that next time it comes around
  // it can be incremented.
  echo QQQ

form method=post action=myself
 ...
 input type=hidden name=iteration value=$iteration /
 ...
/form

?

you should then see a multi-dimensional array with
'print_r($_SESSION);'.

this code is untested and not very complete. ;) but maybe it will give
you some ideas?


hth,
chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and sessions

2004-02-27 Thread Justin Patrin
First of all, make sure you're doing session_start() before 
reading/writing any session data and before you do any output.

Second, You likely need to just do something like this:

session_start();
if(post data) {
  $_SESSION['formArray'][] = $_POST;
}
This will save each POST array as-is in the session.

Chris W. Parker wrote:

Kermit Short mailto:[EMAIL PROTECTED]
on Friday, February 27, 2004 2:10 PM said:

I've got some code and it simply isn't working.  I thought it might be
because each time the form submits data, the array I'm storing
information in is being re-initialized.  If this is the case, I don't
have the multidimensional array I'm trying to get, but just a vector
array with the most recent submission data.


here are some thoughts...

sounds like you're just not keeping track of each iteration. i mean,
within the session variable you need to somehow differentiate between
each subsequent form submittal.
?php

  $iteration = ++$_POST['iteration'];

  $_SESSION['post_data'][$iteration] = $_POST;

  // include $iteration in the post data
  // so that next time it comes around
  // it can be incremented.
  echo QQQ
form method=post action=myself
 ...
 input type=hidden name=iteration value=$iteration /
 ...
/form
?

you should then see a multi-dimensional array with
'print_r($_SESSION);'.
this code is untested and not very complete. ;) but maybe it will give
you some ideas?
hth,
chris.


--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Arrays and performance

2003-11-18 Thread Raditha Dissanayake
Hi,

I belive PHP should be able to handle it but it's a bad idea. The reason 
being your app will not scale. Because if you script consumes 2mb of 
memory on average, 100 users accesing it at the same time will be 200Mb. 
Of course if you expect only a small number of users it does not matter.

The biggest XML job i have handled with PHP is parsing the ODP RDF dump 
which is around 700MB. Obviously arrays are out of the question in such 
a scenario, even though only one user will be accessing the script at a 
given moment. the ODP dump has a couple of million records



Kim Steinhaug wrote:

Something Ive wondered about as I started working with XML.
Importing huge XML files, and converting theese to arrays works
indeed very well. But I am wondering if there are any limits to
how many arrays the PHP can handle when performance is accounted for.
Say I create an array from a XML with lots of childs, say we are
talking of upto 10 childs, which would give 10 dimensional arrays.
Say we then have 10.000 records, or even 100.000 records.
Will this be a problem for PHP to handle, or should I break such
a prosess into lesser workloads (meaning lesser depth in the array)?
Anyone with some experience on this?

 



--
Raditha Dissanayake.

http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 150 KB | with progress bar.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Arrays and performance

2003-11-18 Thread Pablo Gosse
Raditha Dissanayake wrote:

[snip]The biggest XML job i have handled with PHP is parsing the ODP RDF
dump which is around 700MB. Obviously arrays are out of the question in
such a scenario, even though only one user will be accessing the script
At a given moment. the ODP dump has a couple of million records[/snip]

What was your solution for this, Raditha?  How did you handle the
parsing of such a large job?

Cheers,
Pablo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and performance

2003-11-18 Thread Raditha Dissanayake
hi,

In fact i had to handle the ODP dump on two occaisions the first time 
the results went into a mysql db, the second time it went into a series 
of files.

On both occaisions i used SAX parsers. DOM would just roll over and die 
with this much of data. I placed code in the end element handler that 
would either save the data into a db or would save it to a file. In 
either case i only kept the data in memory for a short period. ie from 
the time the start element was detected through the character data 
handling until the end element was detected. (Obviously  i am not 
talking of the root node here :-))

During the whole process you barely noticed the memory usage, however 
the disk usage still went up of course. Reading from disk 1 and writing 
to disk 2 does wonders!

please let me know if you need any further clarifications.

Pablo Gosse wrote:

Raditha Dissanayake wrote:

[snip]The biggest XML job i have handled with PHP is parsing the ODP RDF
dump which is around 700MB. Obviously arrays are out of the question in
such a scenario, even though only one user will be accessing the script
At a given moment. the ODP dump has a couple of million records[/snip]
What was your solution for this, Raditha?  How did you handle the
parsing of such a large job?
Cheers,
Pablo
 



--
Raditha Dissanayake.

http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 150 KB | with progress bar.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Arrays and performance

2003-11-18 Thread Kim Steinhaug
Thanks for your reply!

Im going to use this for a backup system for our webstore system,
where some of our customers have *alot* of products. Given the
structure of the database with categories and images 5000 unique
products quickly gives 3x = 15000 arrays. But again, how often
would the client need to revert the backup? Ive never needed to
do it for now, but I still want to do this backup system in XML
(Looks kinda up to date, :), and at the same time know that it will
eventually work - even for the customers that infact has alot
of products in their system.

The alternative, would be that customers with x products would only
have access to mySQL dump. Or to have a script that evaluates the
XML file and prompts the user that this file is to  large for automatic
import / revert.

a)
From what I understand of your answer you're telling me that PHP
itself will not have any problems working with 1.000.000.000 arrays,
aslong as there are enough ram and processing power available, and
that the timeout is extended. Or would the PHP die a painfull death
as soon as it gets to much data?
Could we coclude the follwing, XMLfile  200 MB = No PHP!

b)
I should do some benchmarking, to find the magic marker for how
much XML data that is affordable to grab when done on a webserver
with other clients to prevent angry customers or failures due to
factory timeout setting to 30 secs.

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---


Raditha Dissanayake [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi,

 I belive PHP should be able to handle it but it's a bad idea. The reason
 being your app will not scale. Because if you script consumes 2mb of
 memory on average, 100 users accesing it at the same time will be 200Mb.
 Of course if you expect only a small number of users it does not matter.

 The biggest XML job i have handled with PHP is parsing the ODP RDF dump
 which is around 700MB. Obviously arrays are out of the question in such
 a scenario, even though only one user will be accessing the script at a
 given moment. the ODP dump has a couple of million records



 Kim Steinhaug wrote:

 Something Ive wondered about as I started working with XML.
 Importing huge XML files, and converting theese to arrays works
 indeed very well. But I am wondering if there are any limits to
 how many arrays the PHP can handle when performance is accounted for.
 
 Say I create an array from a XML with lots of childs, say we are
 talking of upto 10 childs, which would give 10 dimensional arrays.
 Say we then have 10.000 records, or even 100.000 records.
 
 Will this be a problem for PHP to handle, or should I break such
 a prosess into lesser workloads (meaning lesser depth in the array)?
 
 Anyone with some experience on this?
 
 
 


 -- 
 Raditha Dissanayake.
 
 http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
 Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
 Graphical User Inteface. Just 150 KB | with progress bar.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Angelo Zanetti mailto:[EMAIL PROTECTED]
on Tuesday, September 30, 2003 5:43 AM said:

 hi I have a table with rows and each row contains a checkbox ( array)
 and a record. TD of the checkbox:
 echo(td width=15 bgcolor=#9FD9FFinput type=checkbox name=chkR[]
 value=. $chkSessionF[$i] ./td);

Firstly you should be putting double quotes around every value in your
HTML tags.

Revised: (watch wrap)

echo td width=\15\ bgcolor=\#9FD9FF\input type=\checkbox\
name=\chkR[]\ value=\{$chkSessionF[$i]}\/td;

I also changed

. $chkSessionF[$i] .

into

{$chkSessionF[$i]}

.

You can do it either way. I prefer the latter.

If you're not sure what a value is use print_r() to determine it.

echo pre;
print_r($chk);
echo /pre;

Quick side note on the above code:

You cannot write it like:

echo pre.print_r($chk)./pre;

It will not work.

 can anyone help. this is very strange.

I think your problem may just be the quotes around the values in the
HTML. Give it a shot.



hth,
chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread Jason Wong
On Wednesday 01 October 2003 00:10, Chris W. Parker wrote:

[snip]

 If you're not sure what a value is use print_r() to determine it.

 echo pre;
 print_r($chk);
 echo /pre;

 Quick side note on the above code:

 You cannot write it like:

 echo pre.print_r($chk)./pre;

 It will not work.

You can do this though:

  echo pre, print_r($chk), /pre;

Or if using a recent version of php:

  echo nl2br(print_r($var, 1)); //or something like that

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
No bird soars too high if he soars with his own wings.
-- William Blake
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Jason Wong mailto:[EMAIL PROTECTED]
on Tuesday, September 30, 2003 11:06 AM said:

 echo pre.print_r($chk)./pre;
 
 It will not work.
 
 You can do this though:
 
   echo pre, print_r($chk), /pre;

Well heck, that makes things easier!

What's the difference between using , or . for concatenation? (I thought
they were the same.)



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread Jason Wong
On Wednesday 01 October 2003 02:14, Chris W. Parker wrote:
 Jason Wong mailto:[EMAIL PROTECTED]

 on Tuesday, September 30, 2003 11:06 AM said:
  echo pre.print_r($chk)./pre;
 
  It will not work.

Actually, the above *does* work!

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Test-tube babies shouldn't throw stones.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread CPT John W. Holmes
From: Chris W. Parker [EMAIL PROTECTED]

 echo pre.print_r($chk)./pre;

 It will not work.

 You can do this though:

   echo pre, print_r($chk), /pre;

Well heck, that makes things easier!

What's the difference between using , or . for concatenation? (I thought
they were the same.)

Using a comma is just like using another echo command. So for the above,
you're effectively saying:

echo pre; echo print_r($chk); echo /pre;

Note that print_r() will (by default) return a 1 (TRUE) upon success, so you
end up with a 1 being printed at the end of your data.

You could also use this method:

echo pre.print_r($chk,TRUE)./pre;

The TRUE causes the output of print_r() to be returned instead of printed
automatically. The benefit to this method is that you don't end up with the
1 being printed.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread CPT John W. Holmes
From: Jason Wong [EMAIL PROTECTED]
 On Wednesday 01 October 2003 02:14, Chris W. Parker wrote:
  Jason Wong mailto:[EMAIL PROTECTED]
 
  on Tuesday, September 30, 2003 11:06 AM said:
   echo pre.print_r($chk)./pre;
  
   It will not work.
 
 Actually, the above *does* work!

It depends on how you define works :)

You'll end up with output like this:

Array
(
[0] = one
[1] = two
[2] = three
)
pre1/pre

which works but is not what was desired. 

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Jason Wong mailto:[EMAIL PROTECTED]
on Tuesday, September 30, 2003 11:27 AM said:

 echo pre.print_r($chk)./pre;
 
 It will not work.
 
 Actually, the above *does* work!

Not for me. (Although we may be testing different things.)

?

$pageTitle = Checkout Step One;

echo pre.print_r($pageTitle)./pre;
?

Gives me:

Checkout Step Onepre1/pre


If I use the , it's a little closer but still not correct (at least not
what I want). With , I get:

preCheckout Step One1/pre

Close but I don't know where the one is coming from. Maybe it's saying
it's 'true'?



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
CPT John W. Holmes mailto:[EMAIL PROTECTED]
on Tuesday, September 30, 2003 11:32 AM said:

 Note that print_r() will (by default) return a 1 (TRUE) upon success,
 so you end up with a 1 being printed at the end of your data.

[snip]

That answers it!




c.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris Shiflett
--- Chris W. Parker [EMAIL PROTECTED] wrote:
 What's the difference between using , or . for concatenation? (I
 thought they were the same.)

The comma isn't concatenation; echo can take multiple arguments.

I've heard statements about passing multiple arguments to echo being faster
than using concatenation, but every benchmark I've tried myself shows them to
be nearly identical. Feel free to try it yourself and post your results. :-)
I'd be curious to see if others reach the same conclusion.

Chris

=
HTTP Developer's Handbook
 http://shiflett.org/books/http-developers-handbook
My Blog
 http://shiflett.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread CPT John W. Holmes
From: Chris W. Parker [EMAIL PROTECTED]
 CPT John W. Holmes mailto:[EMAIL PROTECTED]
 on Tuesday, September 30, 2003 11:32 AM said:

  Note that print_r() will (by default) return a 1 (TRUE) upon success,
  so you end up with a 1 being printed at the end of your data.

 [snip]

 That answers it!

See... if you'd only have waited that extra second to press the Send button!
;)

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Chris Shiflett mailto:[EMAIL PROTECTED]
on Tuesday, September 30, 2003 11:39 AM said:

 The comma isn't concatenation; echo can take multiple arguments.

Oh ok, I get it.

 I've heard statements about passing multiple arguments to echo being
 faster than using concatenation, but every benchmark I've tried
 myself shows them to be nearly identical. Feel free to try it
 yourself and post your results. :-) I'd be curious to see if others
 reach the same conclusion. 

I tried this, and I think the comma was just slightly faster than the
period. But then again I didn't always get consistent results because I
was trying this out on a machine that is not very fast so the speed at
which is processes something varies quite a bit.

My conclusion was that it's not fast enough to bother changing all my
code, or start writing in a new way.


Although during some testing I did find that writing loops in the
following way is faster than normal.

$counter = -1;
while(++$counter  $amount)
{
// do stuff
}

It made a big enough difference on my slow machine to merit me writing
as many loops in this way as I can. (I think.)



Chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread Jason Wong
On Wednesday 01 October 2003 02:32, Chris W. Parker wrote:
 Jason Wong mailto:[EMAIL PROTECTED]

 on Tuesday, September 30, 2003 11:27 AM said:
  echo pre.print_r($chk)./pre;
 
  It will not work.
 
  Actually, the above *does* work!

 Not for me. (Although we may be testing different things.)

Sorry you're right, it doesn't work. I was testing with php-cli using:

  echo (pre . print_r($_SERVER) . pre);

there was no parse error and I saw some output fly off the console, so I 
thought it had worked :)

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
You can't fall off the floor.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] arrays and php

2003-09-30 Thread Eugene Lee
On Tue, Sep 30, 2003 at 09:10:44AM -0700, Chris W. Parker wrote:
: 
: Angelo Zanetti mailto:[EMAIL PROTECTED]
: on Tuesday, September 30, 2003 5:43 AM said:
: 
:  hi I have a table with rows and each row contains a checkbox ( array)
:  and a record. TD of the checkbox:
:  echo(td width=15 bgcolor=#9FD9FFinput type=checkbox name=chkR[]
:  value=. $chkSessionF[$i] ./td);
: 
: Firstly you should be putting double quotes around every value in your
: HTML tags.
: 
: Revised: (watch wrap)
: 
: echo td width=\15\ bgcolor=\#9FD9FF\input type=\checkbox\
: name=\chkR[]\ value=\{$chkSessionF[$i]}\/td;

A heredoc is more readable:

echo HTMLTAG
td width=15 bgcolor=#9FD9FFinput type=checkbox name=chkR[]
value={$chkSessionF[$i]}/td
HTMLTAG;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Eugene Lee mailto:[EMAIL PROTECTED]
on Tuesday, September 30, 2003 2:12 PM said:

 A heredoc is more readable:
 
 echo HTMLTAG
 td width=15 bgcolor=#9FD9FFinput type=checkbox name=chkR[]
 value={$chkSessionF[$i]}/td
 HTMLTAG;

Yeah, but I don't like those. :P


chris.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread David Nicholson
Hello,

This is a reply to an e-mail that you wrote on Tue, 22 Jul 2003 at
17:40, lines prefixed by '' were originally written by you.
 I need it to echo
 out a
 table with all the A's first, then a blank line, then all the B's,
a
 blank
 line and so on. I could write 26 different queries, one for each
 letter of
 the alphabet, but surely there is a tidier way.

How about:
for($i=a;$i=z;$i++){
echo H1Items beginning with the letter $i/H1;
$arrayposition = 0;
while(strtolower(substr($data[$arrayposition],0,1))==$i){
echo $data[$arrayposition] . BR /;
$arrayposition++;
}
}

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirely in PHP)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread Liam Gibbs
I need it to echo out a table with all the A's first, then a blank line,
then all the B's, a blank line and so on. I could write 26 different
queries, one for each letter of the alphabet, but surely there is a tidier
way.

Do a query, sorting by the field you need alphabetized. Then do this (and
tidy it up as you need):

echo table;
while($result = mysql_fetch_row$(query)) {
   if(substr($result, 0, 1) != $previousfirstletter) {
  $previousfirstletter = substr($result, 0, 1);
  echo trth$previousfirstletter/th/tr;
   }
   echo trtd$result/td/tr;
}

echo /table;

It's untested, but I believe it will work.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread Evan Nemerson
/* UNTESTED - and prolly could be more efficient */
$c = $d = '';
natsort($info);
foreach ( $info as $i ) {
$d = substr($i, 0, 1);
if ( $d != $c )
echo \n;
echo $i;
$c = $d;
}


On Tuesday 22 July 2003 09:40 am, Don Mc Nair wrote:
 Hi folks

 I am trying to print out a table of elements in alphabetical order. I have
 an SQL query which sorts out the data in order and am using 'while ($info
 =(mysql_fetch_row...etc)) to read the data array. I need it to echo out a
 table with all the A's first, then a blank line, then all the B's, a blank
 line and so on. I could write 26 different queries, one for each letter of
 the alphabet, but surely there is a tidier way.

 Any help is appreciated.

 Don


 ---
 Outgoing mail is certified Virus Free.
 Checked by AVG anti-virus system (http://www.grisoft.com).
 Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003

-- 
He who fights too long against dragons becomes a dragon himself; and if you 
gaze too long into the abyss, the abyss will gaze into you.

-Nietzche


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Arrays

2003-03-16 Thread John W. Holmes
 $var = array (
 'AN' = array (
   'Description' = 'Accession Number: (AN)',
   'ReferenceURL' = 'AN__Accession_Number.jsp',
   ),
  'AU' = array (
   'Description' = 'Author(s): (AU)',
   'ReferenceURL' = 'AU__Author(s).jsp',
   )
 )
 
 What I want to get is the keys 'AN' and 'AU' as values.
 
 while (??){
 echo This key is $var[??]br;
 }
 
 This key is AN
 This key is AU

foreach($var as $key = $value)
{ echo The key is $key; }

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays

2003-03-16 Thread John Taylor-Johnston
Thanks!

John W. Holmes wrote:

  $var = array (
  'AN' = array (
'Description' = 'Accession Number: (AN)',
'ReferenceURL' = 'AN__Accession_Number.jsp',
),
   'AU' = array (
'Description' = 'Author(s): (AU)',
'ReferenceURL' = 'AU__Author(s).jsp',
)
  )
 
  What I want to get is the keys 'AN' and 'AU' as values.
 
  while (??){
  echo This key is $var[??]br;
  }
 
  This key is AN
  This key is AU

 foreach($var as $key = $value)
 { echo The key is $key; }

 ---John W. Holmes...

 PHP Architect - A monthly magazine for PHP Professionals. Get your copy
 today. http://www.phparch.com/

--
John Taylor-Johnston
-
If it's not open-source, it's Murphy's Law.

  ' ' '   Collège de Sherbrooke:
 ô¿ô   http://www.collegesherbrooke.qc.ca/languesmodernes/
   - Université de Sherbrooke:
  http://compcanlit.ca/
  819-569-2064



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Marek Kilimajer
Cannot you just make MaSQL count it?

$query = select sum(goals), sum(assists), sum(points) from roster;



Beauford.2002 wrote:

Hi,

I have an array which I am trying to total but having some problems. Any
help is appreciated.
Example:  This is a hockey team and there are 20 players - I am selecting
the goals, assists, and points from each player and then want to have a
grand total of all goals, assists, and points.
$query = select goals, assists, points from roster;

while ($line = mysql_fetch_row($result)) {

$totals[] = $line;

}

I want to total $totals[0][4] through $totals[19][4], $totals[0][5] through
$totals[19][5], etc. for each stat. I thought of putting them in a for loop
and just adding them, but this seemed kind of messy and the long way around
Thanks



 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
It gets a little more complicated than this. There are several teams (each
with 20 players) and then there is the team owner and then there is the
player position, etc.  So to do this I would have to do some kind of a join
and so on - and to date haven't been able to figure this out with sums. I
would also have to do a second query (I am already doing one to get the
points for each player), so I might as well just use it and through the
results in an array and then total it from there - and thus my question of
how I total the array


- Original Message -
From: Marek Kilimajer [EMAIL PROTECTED]
To: Beauford.2002 [EMAIL PROTECTED]
Cc: PHP General [EMAIL PROTECTED]
Sent: Sunday, March 02, 2003 11:10 AM
Subject: Re: [PHP] Arrays and MySQL


 Cannot you just make MaSQL count it?

 $query = select sum(goals), sum(assists), sum(points) from roster;




 Beauford.2002 wrote:

 Hi,
 
 I have an array which I am trying to total but having some problems. Any
 help is appreciated.
 
 Example:  This is a hockey team and there are 20 players - I am selecting
 the goals, assists, and points from each player and then want to have a
 grand total of all goals, assists, and points.
 
 $query = select goals, assists, points from roster;
 
 while ($line = mysql_fetch_row($result)) {
 
 $totals[] = $line;
 
 }
 
 I want to total $totals[0][4] through $totals[19][4], $totals[0][5]
through
 $totals[19][5], etc. for each stat. I thought of putting them in a for
loop
 and just adding them, but this seemed kind of messy and the long way
around
 
 Thanks
 
 
 
 
 
 


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Jason Wong
On Sunday 02 March 2003 23:34, Beauford.2002 wrote:
 Hi,

 I have an array which I am trying to total but having some problems. Any
 help is appreciated.

 Example:  This is a hockey team and there are 20 players - I am selecting
 the goals, assists, and points from each player and then want to have a
 grand total of all goals, assists, and points.

 $query = select goals, assists, points from roster;

 while ($line = mysql_fetch_row($result)) {

 $totals[] = $line;

 }

 I want to total $totals[0][4] through $totals[19][4], $totals[0][5] through
 $totals[19][5], etc. for each stat. I thought of putting them in a for loop
 and just adding them, but this seemed kind of messy and the long way around

You can use array_sum().

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Man's unique agony as a species consists in his perpetual conflict between
the desire to stand out and the need to blend in.
-- Sydney J. Harris
*/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Leo Spalteholz
On March 2, 2003 01:53 pm, Jason Wong wrote:
 On Sunday 02 March 2003 23:34, Beauford.2002 wrote:
  Hi,
 
  I have an array which I am trying to total but having some
  problems. Any help is appreciated.
 
  Example:  This is a hockey team and there are 20 players - I am
  selecting the goals, assists, and points from each player and
  then want to have a grand total of all goals, assists, and
  points.
 
  $query = select goals, assists, points from roster;
 
  while ($line = mysql_fetch_row($result)) {
 
  $totals[] = $line;
 
  }
 
  I want to total $totals[0][4] through $totals[19][4],
  $totals[0][5] through $totals[19][5], etc. for each stat. I
  thought of putting them in a for loop and just adding them, but
  this seemed kind of messy and the long way around

 You can use array_sum().

What about SELECT SUM(Goals), SUM(assists)?

Leo

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
 You can use array_sum().

I have used that in the past, but only on single arrays, I can't figure out
how to do on multi-level arrays, and since I need to have different totals
from different levels of the array, I don't think this will work. If you can
shed some light on this it would be appreciated.

From below - $totals[0][4] through $totals[19][4] , $totals[0][5] through
$totals[19][5], etc.


- Original Message -
From: Jason Wong [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, March 02, 2003 4:53 PM
Subject: Re: [PHP] Arrays and MySQL


 On Sunday 02 March 2003 23:34, Beauford.2002 wrote:
  Hi,
 
  I have an array which I am trying to total but having some problems. Any
  help is appreciated.
 
  Example:  This is a hockey team and there are 20 players - I am
selecting
  the goals, assists, and points from each player and then want to have a
  grand total of all goals, assists, and points.
 
  $query = select goals, assists, points from roster;
 
  while ($line = mysql_fetch_row($result)) {
 
  $totals[] = $line;
 
  }
 
  I want to total $totals[0][4] through $totals[19][4], $totals[0][5]
through
  $totals[19][5], etc. for each stat. I thought of putting them in a for
loop
  and just adding them, but this seemed kind of messy and the long way
around

 You can use array_sum().

 --
 Jason Wong - Gremlins Associates - www.gremlins.biz
 Open Source Software Systems Integrators
 * Web Design  Hosting * Internet  Intranet Applications Development *
 --
 Search the list archives before you post
 http://marc.theaimsgroup.com/?l=php-general
 --
 /*
 Man's unique agony as a species consists in his perpetual conflict between
 the desire to stand out and the need to blend in.
 -- Sydney J. Harris
 */


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Arrays of strings from regex

2002-12-31 Thread Marek Kilimajer


David Pratt wrote:


Am working through document to collect pieces that match and then insert 
them into an array so they can be used to construct another file.

Looking in my doc for lines like this:

{\*\cs43 \additive \sbasedon10 db_edition;}
{\*\cs44 \additive \sbasedon10 db_editor;}
{\*\cs45 \additive \sbasedon10 db_email;}

Wrote this regex to find them:

^\{\\\*\\?(cs[0-9]{1,3}) (.*)\\[a-z0-9]+ (.*);\}$
 

^

I suppose this wants to eat the whole line, use ([^ ]*) - all except space,
or switch to perl expressions with its ungreedy match


Now looking for best method for getting the parts in parenthesis () into an
array so it will contain these values by finding the above three lines:

$matches [0][0][0] = cs43 , \additive \sbasedon10, db_edition
$matches [1][1][1] = cs44 , \additive \sbasedon10, db_editor
$matches [2][2][2] = cs45 , \additive \sbasedon10, db_email

Thanks in advance for any pointers.

 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




  1   2   >