[PHP] RE: New Horizon!

2009-03-02 Thread Alan Lord

Please ignore the previous "New Horizon" message. It is spam and looks like 
someone managed to hack into my hotmail account.

If you wish to, please update your records and use a...@lordies.co.uk in future.

Cheers

Al


_
Free photo editing software from Windows LiveĀ . Try it now! 
http://clk.atdmt.com/UKM/go/134665240/direct/01/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] New Horizon!

2009-03-02 Thread Alan Lord

New Horizon!

i would like to introduce a good company who trades mainly in electornic 
products.
Now the company is under sales promotion,all the products are sold nearly at 
its cost.
They provide the best service to customers,they provide you with original 
products of 
good  quality,and what is more,the price is a surprising happiness to you!
It is realy a good chance for shopping.just grasp the opportunity,Now or never!
The web address: www.vvcnr.com 

_
Free photo editing software from Windows LiveĀ . Try it now! 
http://clk.atdmt.com/UKM/go/134665240/direct/01/

[PHP] Re: Convert Feet to Metres

2005-11-02 Thread Alan Lord

Shaun wrote:

Hi,

I am trying to create a function that will convert metres to feet and vice 
versa. After searching Google I have found that 1 meters = 3.2808399 feet. 
However if someone enters 10.5 to mean 10 feet and 5 inches this is not the 
same as 10 feet and half a foot as there are 12 inches in a foot!


Is there a standard conversion for this problem? 


Make the interface clear (perhaps have separate text boxes for metric or 
imperial entry) so that they enter Feet and Inches rather than a decimal 
notation, which is not common anyway. Then calculate the total inches, 
multiply by 25.4 and divide by 1000.


Of course you also need to handle fractions... Most Americans I believe 
(I'm English) would write 10 5/16" for example.


Hope this helps.

Alan

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



RE: [PHP] Abstract Classes?

2005-10-24 Thread Alan Lord
Ah ha !!!

Thanks Colin, I think I'm getting it now. That makes obvious sense to
think of the abstract class as truly abstract in what it represents...

Only thing is, this where I find most of my thinking about OOP falls
down! 

I seem to be able to think of hundreds of classes which would be
"abstract" [in the true meaning of the word] and I find it quite a
struggle to come up up with useful classes that actually do represent
real world objects :-) But that's just down my own
ignorance/inexperience I think...

Thanks for all the replies to this slightly OT post.

Al


Colin Shreffler wrote:
> I don't particularly care for this explanation as it makes abstract
classes
> out to be a mere convention of some kind during the development
life-cycle.
> 
> While I can see this as a potentially convenient byproduct of the fact
that
> an abstract class cannot be directly instantiated, this is NOT the
whole
> story as they do have a much greater purpose:  They provide
polymorphism and
> encapsulation to class hierarchies.
> 
> Certainly you can't instantiate an abstract class, but abstract
classes
> exist so that the implementation details of certain methods can be
deferred
> to their derived classes further down the inheritance hierarchy.
Abstract
> classes can also contain implementations for other non abstract
methods.
> 
> Abstract classes and Interfaces can be used in combination in MANY
different
> patterns and frameworks.
> 
> I think that I know what you might be getting at here, but it is not
true to
> say it would be a class that shouldn't be instantiated as a 'sanity
check'
> for junior developers.  It should be used to define classes that are
truly
> abstract; those where it doesn't necessarily make sense to have a
'physical'
> manifestation but where it would provide reusable code to its derived
> classes.
> 
> An example of an abstract class might be 'Vehicle'.  Well that is too
vague
> (abstract) so you wouldn't really instantiate it.  Instead you'd
define more
> useable derived 'concrete' classes like Car, Truck, Scooter, Airplane,
> Bicycle, or Skateboard.  Each of these are well defined so it makes
sense
> for these to non-abstract.
> 
> Each of these derived classes would then override the Vehicle's
abstract
> function start() for example, because each one would do this in a
different
> way.  But by defining 'Vehicle' as abstract and defining the abstract
> function start() in it (because 'Vehicle' itself would not have an
> implementation for start()), you guarantee that each derived class
MUST
> provide its own unique implementation for that function.
> 
> Colin
> 
> -Original Message-
> From: Richard Lynch [mailto:[EMAIL PROTECTED] 
> Sent: Sunday, October 23, 2005 11:12 PM
> To: Alan Lord
> Cc: 'Jasper Bryant-Greene'; php-general@lists.php.net
> Subject: RE: [PHP] Abstract Classes?
> 
> On Sun, October 23, 2005 5:40 am, Alan Lord wrote:
> 
>>But what benefit is there is having it as an explicitly "abstract"
>>class? Why can't it just be a "normal" class definition which you
>>inherit from?
> 
> 
> It could be just a normal class...
> 
> But assume you're working on a team with a LOT of programmers, which
> is where OO really shines.
> 
> Then assume some of those programmers are... less experienced... than
> others.


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



RE: [PHP] Abstract Classes?

2005-10-23 Thread Alan Lord
Thanks,

That's starting to make some sence now!

Al 

> -Original Message-
> From: Colin Shreffler [mailto:[EMAIL PROTECTED] 
> Sent: 23 October 2005 17:03
> To: Alan Lord; 'Jasper Bryant-Greene'
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Abstract Classes?
> 
> One reason would be that you might not know the details of a 
> derived class's implementation details at design time.
> 
> For instance I could have an abstract class such as this:
> 
> Class MyTestClass
> {
> function doSomething()
> {
> doSomethingElse();
> }
> 
> abstract function doSomethingElse() ; }
> 
> As you can see I have an abstract function with no details.  
> I know that when the doSomething() function is called it must 
> call the doSomethingElse Function, but at the time that I 
> define MyTestClass I don't know what that is exactly.
> 
> Now say another developer needs to derive a class from 
> MyTestClass.  Because the base class is abstract they must 
> define an emplementation for the doSomethingElse class such as:
> 
> Class MyDerivedClass extends MyTestClass {
> function doSomethingElse()
> {
> // here the developer must specify the specifics of 
> what this method does
> }
> }
> 
> Now in our business logic if we do the following:
> 
> $myClass = new MyDerivedClass();
> $myClass->doSomething();
> 
> The code will actually execute the doSomethingElse()  
> implementation that has been defined in MyDerivedClass.
> 
> This can be extremely useful in developing frameworks that 
> you want other developers to extend on their own and also in 
> business systems where you might need to maintain a system by 
> adding new classes/implementations over time.  Certain 
> patterns also make heavy uses of interfaces and abstract classes.
> 
> Perhaps a real-world example would make more sense.  Does 
> this help?  If not, let me know and I'll come up with a 
> similar/real-world example.
> 
> Colin
> 
> On 10/23/05 4:40 AM, "Alan Lord" <[EMAIL PROTECTED]> wrote:
> 
> > Thanks Jasper,
> > 
> > That makes sense.
> > 
> > But what benefit is there is having it as an explicitly "abstract"
> > class? Why can't it just be a "normal" class definition which you 
> > inherit from?
> > 
> > Sorry to be so dense
> > 
> > Al
> > 
> >> -Original Message-
> >> From: Jasper Bryant-Greene [mailto:[EMAIL PROTECTED]
> >> Sent: 23 October 2005 09:19
> >> To: Alan Lord
> >> Cc: php-general@lists.php.net
> >> Subject: Re: [PHP] Abstract Classes?
> >> 
> >> On Sun, 2005-10-23 at 08:54 +0100, Alan Lord wrote:
> >>> Hi All,
> >>> 
> >>> I have started reading a couple of books about PHP 5 and
> >> whilst most
> >>> of it is comprehensible even to me :-), I fail to
> >> understand WHY there
> >>> is such a thing as an abstract class or method?
> >>> 
> >>> I think I understand what it is: A class that can't itself be 
> >>> instantiated, only inherited from, or a method that
> >> describes itself
> >>> only in terms of what properties it accepts but no implementation 
> >>> detail.
> >>> 
> >>> But could someone explain why I would want to use this? I'm
> >> sure it is
> >>> very useful but I can't quite see the benefit...
> >> 
> >> Hi Alan
> >> 
> >> Here's an example from an application framework I've been 
> working on.
> >> 
> >> It has classes to represent the different HTTP response statuses 
> >> (like
> >> 301 Moved Permanently, 304 Not Modified etc.) with required and 
> >> forbidden headers for each and different characteristics (like no 
> >> request-body allowed etc).
> >> 
> >> I have an Abstract class called HTTP_Response, from which 
> >> HTTP_Response_Moved_Permanently, 
> HTTP_Response_Not_Modified, and many 
> >> others all inherit.
> >> 
> >> The reason HTTP_Response is abstract is because there's no 
> such thing 
> >> as an HTTP_Response on its own. It has to be a specific 
> type of HTTP 
> >> Response, that is a 301 Moved Permanently or a 304 Not Modified.
> >> 
> >> Does that help?
> >> 
> >> --
> >> Jasper Bryant-Greene
> >> General Manager
> >> Album Limited
> >> 
> >> e: [EMAIL PROTECTED]
> >> w: http://www.album.co.nz/
> >> p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
> >> a: PO Box 579, Christchurch 8015, New Zealand
> >> 
> >> 
> 
> 
> Thank you,
> Colin Shreffler
> Principal
> 303.349.9010 - cell
> [EMAIL PROTECTED]
> 
> Warp 9 Software, LLC.
> 6791 Halifax Avenue
> Castle Rock, CO 80104
> 
> Confidentiality Notice: The information in this e-mail may be 
> confidential and/or privileged. This e-mail is intended to be 
> reviewed by only the individual or organization named in the 
> e-mail address. If you are not the intended recipient, you 
> are hereby notified that any review, dissemination or copying 
> of this e-mail and attachments, if any, or the information 
> contained herein, is strictly prohibited.
> 
> 
> 
> 
> 
> 

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



RE: [PHP] Abstract Classes?

2005-10-23 Thread Alan Lord
Thanks Jasper,

That makes sense. 

But what benefit is there is having it as an explicitly "abstract"
class? Why can't it just be a "normal" class definition which you
inherit from?

Sorry to be so dense

Al 

> -Original Message-
> From: Jasper Bryant-Greene [mailto:[EMAIL PROTECTED] 
> Sent: 23 October 2005 09:19
> To: Alan Lord
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Abstract Classes?
> 
> On Sun, 2005-10-23 at 08:54 +0100, Alan Lord wrote:
> > Hi All,
> > 
> > I have started reading a couple of books about PHP 5 and 
> whilst most 
> > of it is comprehensible even to me :-), I fail to 
> understand WHY there 
> > is such a thing as an abstract class or method?
> > 
> > I think I understand what it is: A class that can't itself be 
> > instantiated, only inherited from, or a method that 
> describes itself 
> > only in terms of what properties it accepts but no implementation 
> > detail.
> > 
> > But could someone explain why I would want to use this? I'm 
> sure it is 
> > very useful but I can't quite see the benefit...
> 
> Hi Alan
> 
> Here's an example from an application framework I've been working on.
> 
> It has classes to represent the different HTTP response statuses (like
> 301 Moved Permanently, 304 Not Modified etc.) with required 
> and forbidden headers for each and different characteristics 
> (like no request-body allowed etc).
> 
> I have an Abstract class called HTTP_Response, from which 
> HTTP_Response_Moved_Permanently, HTTP_Response_Not_Modified, 
> and many others all inherit.
> 
> The reason HTTP_Response is abstract is because there's no 
> such thing as an HTTP_Response on its own. It has to be a 
> specific type of HTTP Response, that is a 301 Moved 
> Permanently or a 304 Not Modified.
> 
> Does that help?
> 
> --
> Jasper Bryant-Greene
> General Manager
> Album Limited
> 
> e: [EMAIL PROTECTED]
> w: http://www.album.co.nz/
> p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
> a: PO Box 579, Christchurch 8015, New Zealand
> 
> 

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



[PHP] Abstract Classes?

2005-10-23 Thread Alan Lord
Hi All,

I have started reading a couple of books about PHP 5 and whilst most of
it is comprehensible even to me :-), I fail to understand WHY there is
such a thing as an abstract class or method?

I think I understand what it is: A class that can't itself be
instantiated, only inherited from, or a method that describes itself
only in terms of what properties it accepts but no implementation
detail.

But could someone explain why I would want to use this? I'm sure it is
very useful but I can't quite see the benefit...

Thanks in advance

Al 

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



[PHP] Recommended Reading?

2005-10-18 Thread Alan Lord
Hi all,

Forgive this long diatribe, a bit off-topic I know, but it might
stimulate a good discussion...

I have built a few small apps in PHP before and, whilst they work, I
can't but help feeling that I go about the whole thing the WRONG way...

I am not a professional software person (far from it) but I am
reasonably competent in most things "technical". I trained in
Electronics, build my own PCs and Linux systems from scratch, have used
- just for fun - Java, Delphi, Visual Basic, PHP and a little C/C++.

I am now wanting to write my own application (using PHP of course) to do
something "really useful". And I am looking for some recommendations on
reading [books or links] about "how to design" my application and how to
think about the design in it's abstract form before I start writing
code. 

Normally I end up writing little bits of code to solve small problems
and then sort of kludging them together to do something useful. 

I would really like to try and go about this one the RIGHT way.

Thanks in advance.

Al

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



Re: [PHP] test

2005-10-14 Thread Alan Lord

Amazingly Yes!

Dan McCullough wrote:

did it work ;)

On 10/14/05, Alan Lord <[EMAIL PROTECTED]> wrote:


please ignore

--
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



[PHP] test

2005-10-14 Thread Alan Lord

please ignore

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



[PHP] test

2005-10-14 Thread Alan Lord

please ignore. Sorry for the noise.

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



RE: [PHP] RE: Removing Items from an Array

2005-10-13 Thread Alan Lord
Blimey...

That's going to take some de-ciphering... It looks fascinating :-)

Thanks!

Alan

> -Original Message-
> From: Jochem Maas [mailto:[EMAIL PROTECTED] 
> Sent: 13 October 2005 20:53
> To: Alan Lord
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] RE: Removing Items from an Array
> 
> Alan Lord wrote:
> > Hi TG and others,
> > 
> > I think I must be missing something here.
> > 
> > Your example doesn't seem to traverse "down" into a multidim array. 
> > 
> > Also, it appears as though your script assumes that the 
> structure of 
> > the array is known. It isn't and it is retrieved from "far 
> away" and I 
> > have no control over it's structure/depth/size etc... I can take a 
> > good guess at the keys I want to keep and keep those in an 
> array in my config.inc.
> > But I would ideally like to be able to have a function which is as 
> > "array agnostic" as possible.
> 
> shouldn't be 'array paragnostic' or maybe 'array gnostic' - 
> psychic hypertext processor. does what you mean.
> 
> > 
> > I tried to do an "unset($arr[key])" in one of my other attempts at 
> > solving this problem.  But from what I read in the manual (if I 
> > understood correctly :-)), it seems as though you can't 
> really do this 
> > from within a function/routine which is walking through the 
> array at 
> > that time as the array is not re-ordered...
> 
> right so you have to write your own function. and/or maybe 
> combine it with
> array_map() and/or array_filter() ... here is a routine that 
> drills into an array given an array of values that act as the 'path'
> into the array your 'drilling' (can you handle php5?), may be 
> that inspires you a bit:
> 
> /*
>   * eg
> 
> $yourDataSet = array();
> $yourDataSet['A'] = array();
> $yourDataSet['B'] = array();
> $yourDataSet['A']['A'] = array();
> $yourDataSet['B']['B'] = array();
> $yourDataSet['B']['B']['coolstuff'] = array(
>   'foo' => 'bar',
>   'bar' => 'qux',
> );
> 
> ArrayDriller::setSource( $yourDataSet ); $somedata = 
> ArrayDriller::get( array('B','B','coolstuff') )
>   */
> 
> class ArrayDriller
> {
>  static private $source;
> 
>  static public function setSource($var)
>  {
>   // do a check to make sure the keys are associative?
>   if (is_array($var) && count($var)) self::$source = $var;
>  }
> 
>  static public function set($varName, $value = null)
>  {
>  if (is_array(self::$source) && $varName && 
> !is_numeric($varName)) {
>  if (is_array( $varName )) {
>  $tmpArr =& self::$source;
>  while ( 1 ) {
>  self::chkVarName($k = array_shift( $varName ));
>  if ( !count( $varName )) {
>  return ($tmpArr[ $k ] = $value);
>  break;
>  } else if (! isset($tmpArr[ $k ]) || ! 
> is_array($tmpArr[ $k ])) {
>  $tmpArr[ $k ] = array();
>  }
> 
>  $tmpArr =& $tmpArr[ $k ];
>  }
>  } else {
>  self::chkVarName($varName);
>  return (self::$source[ $varName ] = $value);
>  }
>  }
>  }
> 
>  static public function get($varName)
>  {
>  if (is_array(self::$source) && $varName) {
>  if (is_array( $varName )) {
>  $tmpArr =& self::$source;
>  while ( 1 ) {
>  self::chkVarName($k = array_shift( $varName ));
> 
>  /* endpoint */
>  if ( !count( $varName )) {
>  if (@is_array($tmpArr) && 
> array_key_exists($k, $tmpArr)) {
>  return $tmpArr[ $k ];
>  }
>  break;
>  }
>  else if (!array_key_exists($k, $tmpArr) ||
>   !is_array($tmpArr[ $k ]))
>  {
>  // we can go no deeper
>  break;
>  }
> 
>  $tmpArr =& $tmpArr[ $k ];
>  }
>  } else {
>  self::chk

[PHP] RE: Removing Items from an Array

2005-10-13 Thread Alan Lord
Hi TG and others,

I think I must be missing something here.

Your example doesn't seem to traverse "down" into a multidim array. 

Also, it appears as though your script assumes that the structure of the
array is known. It isn't and it is retrieved from "far away" and I have
no control over it's structure/depth/size etc... I can take a good guess
at the keys I want to keep and keep those in an array in my config.inc.
But I would ideally like to be able to have a function which is as
"array agnostic" as possible.

I tried to do an "unset($arr[key])" in one of my other attempts at
solving this problem.  But from what I read in the manual (if I
understood correctly :-)), it seems as though you can't really do this
from within a function/routine which is walking through the array at
that time as the array is not re-ordered...

Thanks and no offence intended, I am just trying to understand... :-)

Alan
--
Tg wrote:

That works just as well, if you have only two levels of depth.  Mostly I
was trying to illustrate how to use $key => $value in a foreach and what
to do if you need to go multiple levels down.  Once you get to the
bottom level, then you can use isset() certainly.

Just wanted to make sure that it was clear what to do with $key and
$subkey relating to the main array ($alldataarr in this example)
-snip-

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



[PHP] RE: Removing Items from an Array - My Solution

2005-10-13 Thread Alan Lord
Hi cc and others.

I have had quite a struggle with this. But finally, the end result looks
quite 
simple...

Here is the array of Keys Names I want to preserve:

$filter = array(
   'CategoryId' => 1, 'CategoryLevel' => 1, 'CategoryName' => 1,
'CategoryParentId' => 1
);

Here is the routine which (for ease, creates a new array containing only
the array 
keys contained in $filter:

foreach ($orig_arr as $key => $data) {

   if (is_array($data)) {
   foreach ($data as $subkey => $subdata) {
 if (isset($filter[$subkey])) {
 $sub_arr[$subkey] = $subdata;
 }
  }
   }
   $new_arr[] = $sub_arr;
}

$new_arr has just what I need :-)

This only works on a two dimensional array. But with a bit of tweaking
and turing 
into a function, it could probably be used on any number of dimensions
by making 
it recursive?

Thanks to the contributors who supplied ideas and knowledge..

If anyone thinks this could be done a better way, please feel free to
comment! 

Alan

> -Original Message-
> From: cc [mailto:[EMAIL PROTECTED] 
> Sent: 13 October 2005 07:43
> To: Alan Lord
> Cc: php-general@lists.php.net
> Subject: Re: Removing Items from an Array
> 
> could Alan give samples about the input and expected output 
> of the black box?
> then we can consider implement it.
> 
> On 10/13/05, Alan Lord <[EMAIL PROTECTED]> wrote:
> > Thanks for the replies gents.
> >
> > I have cludged together something from your solutions but 
> it isn't yet 
> > working. I've been staring at multi-dim arrays all day and 
> am getting 
> > tired, so I'll carry on tomorrow.
> >
> > Thanks again,
> >
> > Alan
> >
> > > -Original Message-
> > > From: Jochem Maas [mailto:[EMAIL PROTECTED]
> > > Sent: 12 October 2005 19:18
> > > To: [EMAIL PROTECTED]
> > > Cc: php-general@lists.php.net; [EMAIL PROTECTED]
> > > Subject: Re: [PHP] Removing Items from an Array
> > >
> > > Id like to continue where TG left off ...
> > >
> > > hth.
> > >
> > > [EMAIL PROTECTED] wrote:
> > > > If I understand what you're asking, then maybe this will help:
> > > >
> > > > $arrset1 = array("Apples" => 3, "Oranges" => 5, 
> "Apricots" => 1);
> > > > $arrset2 = array("Couches" => 6, "Chairs" => 2, "Benches" => 5);
> > > >
> > > > $alldataarr["Fruits"] = $arrset1;
> > > > $alldataarr["Furniture"] = $arrset2;
> > > >
> > > > Say we want to remove "Chairs", and let's do it the hard way:
> > > >
> > > > foreach ($alldataarr as $key => $data) {
> > > >   foreach ($data as $subkey => $subdata) {
> > > > if ($subkey == "Chairs) {
> > > >   unset($alldataarr[$key][$subkey]);
> > > > }
> > > >   }
> > > > }
> > > >
> > > > using foreach $arr as $key => $data you can get the
> > > key/index name as well as the actual value stored in that part of 
> > > your array.  Then all you have to do is refer back up to the main 
> > > array using the current $key/$subkey values as your indexes.
> > > >
> > >
> > > $filter = array(
> > >   'Fruits'=> array('Apples' => 1, 'Oranges' => 1),
> > >   'Furniture' => array('Couches' => 1, 'Chairs' => 1), );
> > >
> > > $alldataarr = array();
> > > $alldataarr["Fruits"] = array("Apples" => 3, "Oranges" => 5, 
> > > "Apricots" => 1); $alldataarr["Furniture"] = array("Couches"
> > > => 6, "Chairs" => 2, "Benches" => 5);
> > >
> > > foreach ($alldataarr as $key => $data) {
> > > if (!isset($filter[$key]) {
> > >   // we want it all;.
> > >   continue;
> > > }
> > > $alldataarr[$key]= array_intersect_keys($data, 
> $filter[$key]); }
> > >
> > >
> > > // heres one I prepared earlier:
> > >
> > >
> > > /**
> > >   * array_intersect_keys()
> > >   *^--- the internal function (php5.x+?)
> > > has no 's'
> > >   *
> > >   * returns the all the items in the 1st array whose keys 
> are found 
> > > in any of the other arrays
> > >   *
> > >   * @

RE: [PHP] Removing Items from an Array

2005-10-12 Thread Alan Lord
Thanks for the replies gents.

I have cludged together something from your solutions but it isn't yet
working. I've been staring at multi-dim arrays all day and am getting
tired, so I'll carry on tomorrow.

Thanks again,

Alan 

> -Original Message-
> From: Jochem Maas [mailto:[EMAIL PROTECTED] 
> Sent: 12 October 2005 19:18
> To: [EMAIL PROTECTED]
> Cc: php-general@lists.php.net; [EMAIL PROTECTED]
> Subject: Re: [PHP] Removing Items from an Array
> 
> Id like to continue where TG left off ...
> 
> hth.
> 
> [EMAIL PROTECTED] wrote:
> > If I understand what you're asking, then maybe this will help:
> > 
> > $arrset1 = array("Apples" => 3, "Oranges" => 5, "Apricots" => 1);
> > $arrset2 = array("Couches" => 6, "Chairs" => 2, "Benches" => 5);
> > 
> > $alldataarr["Fruits"] = $arrset1;
> > $alldataarr["Furniture"] = $arrset2;
> > 
> > Say we want to remove "Chairs", and let's do it the hard way:
> > 
> > foreach ($alldataarr as $key => $data) {
> >   foreach ($data as $subkey => $subdata) {
> > if ($subkey == "Chairs) {
> >   unset($alldataarr[$key][$subkey]);
> > }
> >   }
> > }
> > 
> > using foreach $arr as $key => $data you can get the 
> key/index name as well as the actual value stored in that 
> part of your array.  Then all you have to do is refer back up 
> to the main array using the current $key/$subkey values as 
> your indexes.
> > 
> 
> $filter = array(
>   'Fruits'=> array('Apples' => 1, 'Oranges' => 1),
>   'Furniture' => array('Couches' => 1, 'Chairs' => 1), );
> 
> $alldataarr = array();
> $alldataarr["Fruits"] = array("Apples" => 3, "Oranges" => 5, 
> "Apricots" => 1); $alldataarr["Furniture"] = array("Couches" 
> => 6, "Chairs" => 2, "Benches" => 5);
> 
> foreach ($alldataarr as $key => $data) {
> if (!isset($filter[$key]) {
>   // we want it all;.
>   continue;
> }
> $alldataarr[$key]= array_intersect_keys($data, $filter[$key]); }
> 
> 
> // heres one I prepared earlier:
> 
> 
> /**
>   * array_intersect_keys()
>   *^--- the internal function (php5.x+?) 
> has no 's'
>   *
>   * returns the all the items in the 1st array whose keys are 
> found in any of the other arrays
>   *
>   * @return array()
>   */
> function array_intersect_keys()
> {
>  $args   = func_get_args();
>  $originalArray  = $args[0];
>  $res= array();
> 
>  if(!is_array($originalArray)) { return $res; }
> 
>  for($i=1;$i  if(!is_array($args[$i])) { continue; }
>  foreach ($args[$i] as $key => $data) {
>  if (isset($originalArray[$key]) && !isset($res[$key])) {
>  $res[$key] = $originalArray[$key];
>  }
>  }
>  }
> 
>  return $res;
> }
> 
> 
> 
> 
> > 
> > Basic example, but I think you can modify this to work with 
> what you're doing.
> > 
> > Let me know if you have any questions about this example.
> > 
> > -TG
> > 
> > 
> > 
> > = = = Original message = = =
> > 
> > Hi all,
> > 
> > I'm really struggling here! I have a large, multi-dimensional array 
> > that I want to "clean-up" a bit before committing to a database.
> > 
> > I want to remove quite a bit of the array but using the 
> KEYs not the 
> > values. I know the keys I want to keep and I know the keys 
> I want to 
> > get rid of. I want to keep the structure and sequence of 
> the array in tact.
> > 
> > All of the array traversing functions in PHP seem to 
> either: only work 
> > on the values, or do not allow the removal of elements of the array!
> > 
> > Can anyone offer a clue bat to a tired old array walker!
> > 
> > Thanks
> > 
> > Alan
> > 
> > 
> > ___
> > 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



[PHP] Removing Items from an Array

2005-10-12 Thread Alan Lord
Hi all,

I'm really struggling here! I have a large, multi-dimensional array that
I want to "clean-up" a bit before committing to a database.

I want to remove quite a bit of the array but using the KEYs not the
values. I know the keys I want to keep and I know the keys I want to get
rid of. I want to keep the structure and sequence of the array in tact. 

All of the array traversing functions in PHP seem to either: only work
on the values, or do not allow the removal of elements of the array!

Can anyone offer a clue bat to a tired old array walker!

Thanks

Alan

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



RE: [PHP] Speed/Efficiency Question: Large array into DB

2005-10-11 Thread Alan Lord
Thanks for the reply.

I am indeed importing data, but from far away over the 'net, and it
changes frequently so needs  updating regularly.

I like the idea of creating a file (I'll do it ram rather than a text
file I think) with the insert strings...

Thanks

Alan

> -Original Message-
> From: Brent Baisley [mailto:[EMAIL PROTECTED] 
> Sent: 11 October 2005 19:35
> To: Alan Lord
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Speed/Efficiency Question: Large array into DB
> 
> Sounds to me like you are trying to import data. In which 
> case it would be best to create a text file and import it 
> rather than putting PHP in the middle.
> 
> But if you are going us to PHP, I would not do individual INSERTs.  
> The overhead will really slow things down with number of 
> inserts you are doing. Use the multiple value insert syntax 
> and do multiple bulk inserts or just one big one. Although 
> doing one big one will end up being an all or nothing deal. 
> With multiple bulk inserts, you'd be able to write to a log 
> file between inserts so you can track it's progress.
> 
> I would step through the array, creating the string for 
> inserting (value1, value2, value3, value4),(value1, value2, 
> value3, value4), (value1, value2, value3, value4),...
> 
> 
> On Oct 11, 2005, at 12:28 PM, Alan Lord wrote:
> 
> > Hi All,
> >
> > Not being a professional programmer I am looking for some 
> advice about 
> > the best way to do the following:
> >
> > I have a large multidimensional array (up to 7Mb) It 
> contains a list 
> > of categories in a fairly normal Cat_ID and Parent_ID 
> arrangement. The 
> > array also contains a great deal of superfluous information which I 
> > want to ignore.
> >
> > I wish to walk through the entire array, select 4 key/value 
> pairs from 
> > each sub-array and write those to my Database (Keys are: Cat_ID, 
> > Parent_ID, CatName, CatLevel). I wish to ignore all other 
> key/ values 
> > in each array.
> >
> > I'm guessing that I should use array_walk_recursive() and apply my 
> > test for valid keys then write this into my db... But, should I do 
> > this for each iteration, or make a new array with just the 
> information 
> > I need then write that into my DB? And do I use a 
> transaction/commit 
> > block and try to do the whole thing in one db-write or 
> again, INSERT 
> > on each step through my array?
> >
> > Oh yes, the key names in the array correspond to field names in my 
> > database.
> >
> > Sorry it's a bit long-winded...
> >
> > Thanks in advance for any suggestions.
> >
> > Alan
> >
> > --
> > 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



[PHP] Speed/Efficiency Question: Large array into DB

2005-10-11 Thread Alan Lord
Hi All,

Not being a professional programmer I am looking for some advice about
the best way to do the following:

I have a large multidimensional array (up to 7Mb) It contains a list of
categories in a fairly normal Cat_ID and Parent_ID arrangement. The
array also contains a great deal of superfluous information which I want
to ignore. 

I wish to walk through the entire array, select 4 key/value pairs from
each sub-array and write those to my Database (Keys are: Cat_ID,
Parent_ID, CatName, CatLevel). I wish to ignore all other key/values in
each array.

I'm guessing that I should use array_walk_recursive() and apply my test
for valid keys then write this into my db... But, should I do this for
each iteration, or make a new array with just the information I need
then write that into my DB? And do I use a transaction/commit block and
try to do the whole thing in one db-write or again, INSERT on each step
through my array?

Oh yes, the key names in the array correspond to field names in my
database.

Sorry it's a bit long-winded...

Thanks in advance for any suggestions.

Alan

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



[PHP] retrieving ENUM description from MySQL

2003-11-19 Thread Alan Lord
Hi all,

This is a bit wierd so don't flame please.

Imagine a database table, field defined as ENUM with a list of allowed types
such as
"Mr", "Mrs", "Miss", "Dr", "Prof", etc - you get the idea.

I've read the MySQL manual and by using

SHOW COLUMNS FROM "table_name" LIKE "enum_column_name";

I can get a result.

But the string of ENUMs is not an array. It is returned as a string with all
types in one string.

Anyone got any ideas about how to retrieve it in a better way - else I'll
need to start exploding the string...

Thanks in advance

Al

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



[PHP]

2003-11-12 Thread Alan Lord
Hi all,

can I put a function_name() in the  place holder?
I know I can use a file name, but it would be much better (for me) if I
could use a function name.

Thanks in advance

Al

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



[PHP] intercepting URLs in a "control-system"

2003-10-16 Thread Alan Lord
Please forgive any obvious ignorances on my part, I am just learning PHP...

Having read quite a bit on-line, I am interested in trying to "trap" URLs
sent to my site so I can process the request and respond without
neccessarily having a "real" page to serve. If this makes any sense, how do
I do it? Because I expect that apache (in my case) would not like a URL that
contains extra directories/files and would reject it.

An example:

Web Site Root:

www.abc.com/index.php

On that page are "a" tags to further information but which physically don't
exist. It will be automatically generated from a database. For example:

www.abc.com/cars/volvo/X70.html

If I don't have that directory tree and a file called X70.html. Could I
"trap" the http/URL request (BEFORE apache throws it out) and process it in
my PHP control-engine which will find the right information and respond
accordingly?

Thanks in advance,

Alan

PS, if there are any examples of this (GPL) which you know of, please just
pass me the link.

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