Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    Need Help Building a dataset

    Hi Guys,

    I am trying to build a dataset to use within a chart. My brain for some reason doesn't seem to be connecting the dots tonight on how to achieve what I want. I am looking to combine 3 or more array keys into one array.

    Example.
    PHP Code:
    Array1
    (
        [
    0] => 3
        
    [1] => 8
        
    [2] => 2
    )

    Array2
    (
        [
    0] => 4
        
    [1] => 8
        
    [2] => 1
        
    [3] => 2
        
    [4] => 5
    )

    Array3
    (
        [
    0] => 1
        
    [1] => 2
        
    [2] => 3
        
    [3] => 4

    Now both the array size and array quantities are a variable. I may have 40 arrays to combine or just 3 like this example.

    I need to combine it to look like this.
    PHP Code:
    array
    )
        [
    0] => array(3,4,1)
        [
    1] => array(8,8,2)
        [
    2] => array(2,1,3)
        [
    3] => array(null,2,4)
        [
    4] => array(null,5,null)

    Any help is appreciated. Thanks in advance.

  • #2
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    make array1, 2, and 3 with same name bro.
    PHP Code:
    $data[] = array("3","8","2");
    $data[] = array("4","8","1","2","5");
    $data[] = array("1","2","3","4"); 
    so, you just need to add $data[].

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    How will i handle null entries in the array? What you have suggest isnt exactly what i was looking for, but thank you.

  • #4
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    the length of all array same?

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    no the length of the arrays can change.

  • #6
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    i don't understand why you are worried about null entries.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •