0

I need help figuring out what I am doing wrong and/or if there is a better way to do it, my question is two part. The first part is I am using Joomla 3.5.1 and in the template I have two fieldsets, one that allows the user to enter links to their social media accounts and the second I am attempting to make a sort if you will using a set of drop downs. This may or may not be the best so I am open to options here.

Now for the second part. I am able to bring in the both field sets into separate arrays, for simplicity array 1 and array 2. Array 1 has the links and array 2 has the order. So my question is this, how would be the best way to loop through and match everything up while removing the empties in array 1 and "none" in array 2.

One thought I did have is should array 2 not be multidimensional and let the key be the "soXYZ", but then how would the best way to match it up knowing that the lengths are different and the order as well.

Array 2 where (-1) are "None" in the drop downs

Array
(
[0] => soPhone
[1] => soContact
[2] => soFacebook
[3] => soMap
[4] => -1
[5] => -1
[6] => -1
[7] => -1
[8] => -1
[9] => -1
[10] => -1
[11] => -1
[12] => -1
[13] => -1
[14] => -1
)

Array 1

Array
(
[0] => Array
    (
        [0] => soPhone
        [1] => 555.867.5309
    )

[1] => Array
    (
        [0] => soContact
        [1] => Contact
    )

[2] => Array
    (
        [0] => soMap
        [1] => Map
    )

[3] => Array
    (
        [0] => soFacebook
        [1] => Facebook
    )

[4] => Array
    (
        [0] => soTwitter
        [1] => Twitter
    )

[5] => Array
    (
        [0] => soGoogle
        [1] => Google Plus
    )

[6] => Array
    (
        [0] => soLinkedIn
        [1] => Linked In
    )

[7] => Array
    (
        [0] => soPinterest
        [1] => Pinerest
    )

[8] => Array
    (
        [0] => soYouTube
        [1] => YouTube
    )

[9] => Array
    (
        [0] => soVimeo
        [1] => Vimeo
    )

[10] => Array
    (
        [0] => soYelp
        [1] => Yelp
    )

[11] => Array
    (
        [0] => soInstagram
        [1] => Instagram
    )

[12] => Array
    (
        [0] => soTripAdvisor
        [1] => Trip Advisor
    )

[13] => Array
    (
        [0] => soHouzz
        [1] => Houzz
    )

[14] => Array
    (
        [0] => soAngiesList
        [1] => Angies List
    )

)

Array Result

Array
(
[0] => Array
    (
        [0] => soPhone
        [1] => 555.867.5309
    )

[1] => Array
    (
        [0] => soContact
        [1] => Contact
    )

[2] => Array
    (
        [0] => soFacebook
        [1] => Facebook
    )

[3] => Array
    (
        [0] => soMap
        [1] => Map
    )
)

Any guidance is appreciated.

Chad J Treadway
  • 422
  • 7
  • 20

1 Answers1

0

After the power of posting I was able to eventually get my desired result, which as follows:

I set up three arrays arrLinks (originally Array 1) , arrLinksOrder (originally Array 2) and arrLinksCombined (Array Result), then populated arrLinks with the user entered text links on the template, arrLinksOrder pulls from the drop downs.

My original plan was to have arrLinks be multidimensional but in the end I just set the key's for each in my code.

I then used this stackoverflow link to help combine the arrLinksOrder and arrLinks. Once everything is combined I was able to build the html and really clean up the file to something easier to manage.

Code below:

// Populate the contents of the text-box into an array
    $arrLinks = array( 
        "soFacebook"=> $tbFacebook,
        "soTwitter"=> $tbTwitter,
        "soGoogle"=> $tbGoogle,
        "soLinkedIn"=> $tbLinkedIn,
        "soPinterest"=> $tbPinterest,
        "soYouTube"=> $tbYouTube,
        "soInstagram"=> $tbInstagram,
    );

// Populate an array (arrLinksOrder) with the drop down selections
    for ($i=1; $i < ($linksCount+1); $i++) { 
        $varName = 'listSocialOrder'.$i;
        $arrLinksOrder[$i] = $$varName;  
    }

// Combine arrLinksOrder and arrLinks, if the arrLinksOrder exists in arrLinks
    foreach($arrLinksOrder as $key) {
        if(array_key_exists($key, $arrLinks)) {
            $arrLinksCombined[$key] = $arrLinks[$key];
        }
    }

If anyone has any improvements please feel free to share, this is what worked for me at the time.

Community
  • 1
  • 1
Chad J Treadway
  • 422
  • 7
  • 20