Jump to content

Recommended Posts

Here is the code

 

foreach($response['body']->project as $project){	  

// output only where status is active
if ($project->status == 'active'){		
	$created = $project->{'created-on'};		
	$catagory = $project->company->name;
	$project_name = $project->name;
	$projectId = $project->id;

	$resmilestones = $bc->getMilestonesForProject($projectId,$filter_type='late',$format=null);

	foreach($resmilestones['body']->milestone as $milestone){
	$late_date = $milestone->deadline;
	$responsible = $milestone->{'responsible-party-name'};
	$milestone_name = $milestone->title;

	$milestone_data = $late_date . ' , ' . $responsible . ' , ' . $milestone_name . "\n";



	}




	$data_string .= $projectId .',' . $created .',' . $catagory .',' . $project_name .',' . $late_date . ' , ' . $responsible . ' , ' . $milestone_name . "\n";
}


}

 

in the part

foreach($resmilestones['body']->milestone as $milestone)

i only want to get the first element. i don't need the others some items have none and some have 10 but i just need the first one as it is the Milestone that is the most over due the last one that i am getting now is the least overdue. And i apparently have no clue how to go about this.

Link to comment
https://forums.phpfreaks.com/topic/268516-getting-first-item-of-array/
Share on other sites

I don't think i stated my original issue correctly.

 

output of $resmilestone gives me something like:

 

[body] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [type] => array
                )

            [milestone] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [all-day] => true
                            [commented-at] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [nil] => true
                                        )

                                )

                            [comments-count] => 0
                            [completed] => false
                            [created-on] => 2012-07-27T14:53:29Z
                            [creator-id] => 9459713
                            [id] => 33086455
                            [project-id] => 9115676
                            [responsible-party-id] => 4538224
                            [responsible-party-type] => Person
                            [start-at] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [nil] => true
                                        )

                                )

                            [title] => Creative
                            [wants-notification] => true
                            [type] => Milestone
                            [creator-name] => Lynn
                            [deadline] => 2012-09-06
                            [responsible-party-name] => Michelle
                        )

                    [1] => SimpleXMLElement Object
                        (
                            [all-day] => true
                            [commented-at] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [nil] => true
                                        )

                                )

                            [comments-count] => 0
                            [completed] => false
                            [created-on] => 2012-07-27T14:53:46Z
                            [creator-id] => 9459713
                            [id] => 33086460
                            [project-id] => 9115676
                            [responsible-party-id] => 9459713
                            [responsible-party-type] => Person
                            [start-at] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [nil] => true
                                        )

                                )

                            [title] => Approval
                            [wants-notification] => true
                            [type] => Milestone
                            [creator-name] => Lynn
                            [deadline] => 2012-09-13
                            [responsible-party-name] => Lynn
                        )

                )

        )

    [status] => 200 OK
    [location] => 
)

 

I am getting the info in the

[1]

and i need the one in the

[0]

I hope this sheads a little bit more light on what i am trying to get.

 

Thanks.

  • 1 month later...

I think you need to use the built in PHP function "curent" for this array.

<?php
$theArray = array("first", "second", "third");
print_r(current($theArray));
?>

 

Please look at the reference php.net/manual/en/function.current.php

Edited by shaddowman
  • 3 weeks later...

Sorry for my English !

 

<?php
$milestone = $yourSimpleXmlElementObject->body->milestone[1];

// Because some keys contains characters like '-' , you need to write keys into brackets {}
$created_on = $milestone->{'created-on'};
$title = $milestone->{'title'};
$creator_name = $milestone->{'creator-name'};

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.