Re: [PHP] Array: If i'm in the child array then how I tell the parent's key name..

2005-10-01 Thread Ing . Josué Aranda
Scott, I hope this code help you:

[PHP CODE]
/*
 * Author:
 *   Josue Aranda [EMAIL PROTECTED]
 */

// This set an $arr
$arr=   array(
'ABC' = array(
'DEF' = 'Data'
)
);

print_r($arr);

/*  
 *  Will OutPut:
 *
 *  Array
 *  (
 *  [ABC] = Array
 *  (
 *  [DEF] = Data
 *  )
 *  
 *  )
 */

echo $arr['ABC']['DEF'];// Will Output Data

$level = 0;

foreach ($arr as $key = $value){
$level++;
echo  Level: .$level. Key: .$key;   // Will output Level: 1 Key: 
ABC
foreach ($value as $subKey = $subValue){
$level++;   
echo  Level: .$level. Key: .$subKey;// Will OutPut 
Level: 2 Key: DEF
$level--;
}
$level--;
}
[/PHP CODE]

are you trying to make some kind of tree?



On 9/30/05, Scott Fletcher [EMAIL PROTECTED] wrote:
 Suppose that I'm in a child array and I wanna know how do I tell what key is
 the parent's level, one level up...

 For example,

 --snip--
   $arr['ABC']['DEF'];
 --snip--

 Let's say the child is DEF then the key name one level up would be ABC.
 How do I determine the one level up?

 Thanks...

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




--




JOSUE ARANDA
http://josuearanda.com

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



[PHP] string to .ZIP | sending report by email

2005-08-23 Thread Ing . Josué Aranda
I have a script that generate a XHTML report, but also i want to send
that report by email, the problem is the file size its up to 4Mb, its
too big to send by email (considering that some people still using
hotmail).. how i can send it compressed by email? anyone knows a class
that can help me?
any suggestions are welcome :D thanks
-- 


JOSUE ARANDA

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



Re: [PHP] php as standalone?

2005-08-23 Thread Ing . Josué Aranda
mybe this can help...

http://www.dwebpro.com/

with this app you can us a CD or DVD like a stand alone for
distributing your php script

:D


On 8/23/05, Thomas [EMAIL PROTECTED] wrote:
 Hi there,
 
 
 
 I am going to take that chance now to ask if it is viable to create a
 standalone app with php and gtk+, fully realizing that this IS the php list
 ;-)
 
 I was thinking of php/gtk+ because I need that as a cross-platform
 application. What I really would like is to have .rpm's and .exe's created,
 so one can include them in the OS startup. Is this possible at all with php?
 Has anyone worked with php to create standalone apps?
 
 
 
 I essentially want to be able to auto update and synchronize a local xml
 based database with an online one (ok, plus doing some viewing and creating
 of reports, and so on, and so forth . )
 
 
 
 Alternatives could be: mono, qt (arrgh), mozilla/xul (any done that?) or
 Java :-( .
 
 
 
 Any thoughts on that?
 
 
 
 Thomas
 
 
 


-- 


JOSUE ARANDA

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



Re: [PHP] counting nested array

2005-08-17 Thread Ing . Josué Aranda
hahaha, thanks robin you save some seconds of mi life... it looks more
pro with that if...

On 8/17/05, Robin Vickery [EMAIL PROTECTED] wrote:
 On 8/17/05, Ing. Josué Aranda [EMAIL PROTECTED] wrote:
  OK this the little function i made to solve this..
 
  function countNested($array){
  foreach($array as $value){
  if(is_array($value))
  $total=$this-countNested($value)+$total;
  }else{
  $total=$total+1;
  }
  }
  return $total;
  }
 
 Looks OK-ish - there's a missing '{' on the third line but apart from
 that it should work fine as a class method.
 
  any optimizations are welcome
 
 You can simplify the if-block as below, which might save you as much
 as a microsecond or two :-)
 
function countNested($array){
   $total = 0;
foreach ($array as $value) {
$total += is_array($value) ? $this-countNested($value) : 1;
}
return $total;
}
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 


JOSUE ARANDA

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



[PHP] counting nested array

2005-08-16 Thread Ing . Josué Aranda
Hi to everyone..

now i have a little problem counting an nested array. Im using it to
fill a Java TreeView... it looks like this:

[1] = Array
(
[1] = Array
(
[1] = Array
(
[1] = LECHE PREMIUM 1 LT
[2] = LECHE PREMIUM 1/2 GL
[3] = LECHE PREMIUM 1 GL
)

[2] = Array
(
[1] = LECHE LIGHT 1 LT
[2] = LECHE LIGHT 1/2 GL
[3] = LECHE FRESCA 1 GL LIGHT
)

[3] = Array
(
[1] = LECHE SEMI 1 LT FRESCA
[2] = LECHE DESLACTOSADA 21 DIAS 1 LT
[3] = LECHE SILUETTE 21 DIAS 1 LT
[4] = LECHE DESARROLLO 21 DIAS 1 LT
[5] = LECHE ENTERA 21 DIAS 1 LT
[6] = LECHE LIGHT 21 DIAS 1 LT
)

[5] = Array
(
[1] = LECHE FRESCA 1 GL SEMIDESCREMADA BELL
[2] = LECHE FRESCA 1/2 GL SEMIDESCREMADA BELL
)

[6] = Array
(
[1] = LECHE FRESCA 1 GL LIGHT BELL
[2] = LECHE FRESCA 1/2 GL LIGHT BELL
[3] = LECHE FRESCA 1 LT LIGHT BELL
)

[7] = Array
(
[1] = LECHE FRESCA 1 GL ENTERA BELL
[2] = LECHE FRESCA 1/2 GL ENTERA BELL
[3] = LECHE FRESCA 1LT ENTERA BELL
)

)


The number of the branches is not always the same.. (it depends on the
query).. when i use count($array, COUNT_RECURSIVE) for nested arrays..
it give to me the total including the nodes in the branches ( in this
case 28).. now here is the question, how i can get only the last nodes
in this case ... exist a easy way to do it?. or its necessary to make
a funcion with a bunch of foreach?.. any suggestions are welcome =o) 
thanks!
-- 


JOSUE ARANDA

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



Re: [PHP] counting nested array

2005-08-16 Thread Ing . Josué Aranda
OK this the little function i made to solve this..
[CODE]

function countNested($array){
foreach($array as $value){
if(is_array($value))
$total=$this-countNested($value)+$total;
}else{
$total=$total+1;
}
}
return $total;
}

[/CODE]

any optimizations are welcome



On 8/16/05, Robin Vickery [EMAIL PROTECTED] wrote:
 On 8/16/05, Ing. Josué Aranda [EMAIL PROTECTED] wrote:
 
  The number of the branches is not always the same.. (it depends on the
  query).. when i use count($array, COUNT_RECURSIVE) for nested arrays..
  it give to me the total including the nodes in the branches ( in this
  case 28).. now here is the question, how i can get only the last nodes
  in this case ... exist a easy way to do it?. or its necessary to make
  a funcion with a bunch of foreach?.. any suggestions are welcome =o)
  thanks!
 
 If I understand you correctly, you only want the leaves of your tree -
 in your example, that would be 20?
 
 I don't think there's a convenient builtin function that'll do it, but
 it's not hard to write your own:
 
 ?php
 
 function leaf_count($item) {
   $count = 0;
 
   if (!is_array($item)) { return 1; }
 
   foreach ($item as $element) {
 $count += leaf_count($element);
   }
 
   return $count;
 }
 
 print leaf_count($array);
 
 ?
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


-- 


JOSUE ARANDA

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